1
+ # Simple Linear Regression
2
+ # Importing the libraries
3
+ import numpy as np
4
+ import pandas as pd
5
+ import pickle
6
+
7
+ # Importing the dataset
8
+ dataset = pd .read_csv ('/home/soumitra/Working/Salary_Data.csv' )
9
+ X = dataset .iloc [:, :- 1 ].values
10
+ y = dataset .iloc [:, 1 ].values
11
+
12
+ # Splitting the dataset into the Training set and Test set
13
+ from sklearn .cross_validation import train_test_split
14
+ X_train , X_test , y_train , y_test = train_test_split (X , y , test_size = 0.33 ,random_state = 0 )
15
+
16
+ # Feature Scaling
17
+ """from sklearn.preprocessing import StandardScaler
18
+ sc_X = StandardScaler()
19
+ X_train = sc_X.fit_transform(X_train)
20
+ X_test = sc_X.transform(X_test)
21
+ sc_y = StandardScaler()
22
+ y_train = sc_y.fit_transform(y_train)"""
23
+
24
+ # Fitting Simple Linear Regression to the Training set
25
+ from sklearn .linear_model import LinearRegression
26
+ regressor = LinearRegression ()
27
+ regressor .fit (X_train , y_train )
28
+
29
+ # Predicting the Test set results
30
+ y_pred = regressor .predict (X_test )
31
+ coef_ = regressor .coef_
32
+ intercept_ = regressor .intercept_
33
+
34
+ # Score of prediction model
35
+ from sklearn .metrics import r2_score
36
+ score = r2_score (y_test , y_pred )
37
+ pickle .dump ([y_pred , score , coef_ , intercept_ ], open ("/home/soumitra/attributes.p" , "wb" ), protocol = 2 )
0 commit comments