Back to Modin

Modin Scikit Learn Example

examples/modin-scikit-learn-example.ipynb

0.37.11.0 KB
Original Source
python
%matplotlib inline

import numpy as np
import modin.pandas as pd
import matplotlib.pyplot as plt
import sklearn
python
data = pd.read_csv("data/boston_housing.csv")

data.head()
python
features = data.drop("PRICE", axis=1)
labels = data["PRICE"]

type(features)
python
from sklearn.linear_model import LinearRegression

lm = LinearRegression()
lm.fit(features, labels)
python
plt.scatter(data["RM"], labels)
plt.xlabel("Average number of rooms per dwelling")
plt.ylabel("Housing Price")
plt.title("Relationship between Rooms and Price")
plt.show()
python
predicted_prices = lm.predict(features)
python
plt.scatter(labels, predicted_prices)
plt.xlabel("Prices")
plt.ylabel("Predicted Prices")
plt.title("Prices versus Predicted Prices")
plt.show()
python
training_error = \
    (labels - predicted_prices).apply(lambda x: x ** 2).mean()

training_error
python
# Citation: http://bigdata-madesimple.com/how-to-run-linear-regression-in-python-scikit-learn/