Guest User

Untitled

a guest
Apr 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. dataset = pd.read_csv('Av cost prediction.csv')
  5. X = dataset.iloc[:,:-1].values
  6. Y = dataset.iloc[:,1].values
  7. from sklearn.cross_validation import train_test_split
  8. X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.2,random_state = 0)
  9. from sklearn.linear_model import LinearRegression
  10. regressor = LinearRegression()
  11. regressor.fit(X_train,Y_train) # fitted and trained the regressor object on the training set of X and Y.Created a unique linear regression equation for entire dataset
  12. y_pred = regressor.predict(X_test)
  13. plt.scatter(X_train,Y_train,color = 'green')
  14. plt.plot(X_train,regressor.predict(X_train),color = 'red')
  15. plt.title('Month Vs Cost(Training data)')
  16. plt.xlabel('Month')
  17. plt.ylabel('Cost')
  18. plt.show()
  19. plt.scatter(X_test,Y_test,color = 'green')
  20. plt.plot(X_train,regressor.predict(X_train),color = 'red')
  21. plt.title('Month Vs cost(Test data)')
  22. plt.xlabel('Month')
  23. plt.ylabel('Cost')
  24. plt.show()
Add Comment
Please, Sign In to add comment