Skip to content

Instantly share code, notes, and snippets.

@hanasuru
Last active March 12, 2019 11:03
Show Gist options
  • Save hanasuru/26bca4e310580cc16e437db665427383 to your computer and use it in GitHub Desktop.
Save hanasuru/26bca4e310580cc16e437db665427383 to your computer and use it in GitHub Desktop.
linear-regression
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
dataset = pd.read_csv('machine.csv')
X = dataset[['125', '256', '6000','256.1','16','128']]
Y = dataset['198']
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, random_state=0)
regressor= LinearRegression()
regressor.fit(X_train, y_train)
coeff_df = pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])
y_pred = regressor.predict(X_test)
df = pd.DataFrame({'Actual': y_test, 'Predicted': y_pred})
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment