Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Fri Jul 12 19:10:27 2019
  5.  
  6. @author: nodeflux
  7. """
  8.  
  9. import numpy
  10. import pandas
  11. from matplotlib import pyplot
  12. from sklearn.model_selection import train_test_split
  13. from sklearn.linear_model import LinearRegression
  14. from sklearn.metrics import mean_squared_error, r2_score
  15.  
  16.  
  17. dataset = pandas.read_csv('/home/nodeflux/Documents/mercubuana/UAS_DATA_MINING/data.csv')
  18. x = dataset.iloc[:, :-1].values
  19. y = dataset.iloc[:, 2]
  20.  
  21.  
  22. x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=0)
  23. regressor = LinearRegression()
  24. regressor.fit(x_train, y_train)
  25.  
  26. y_prediction = regressor.predict(x_test)
  27.  
  28. # Coefficient
  29. print('Coefficient: \n', regressor.coef_)
  30. # Mean Squared Error
  31. print("Mean squared error: %.2f" % mean_squared_error(y_test, y_prediction))
  32. # Variance score
  33. print("Variance score: %.2f" % r2_score(y_test, y_prediction))
  34.  
  35. pyplot.scatter(x_test[:, 0], y_test, color='black')
  36. pyplot.scatter(x_test[:, 0], y_prediction, color='blue', linewidth=3)
  37. pyplot.xticks(())
  38. pyplot.yticks(())
  39. pyplot.show()
  40.  
  41. pyplot.scatter(x_test[:, 1], y_test, color='black')
  42. pyplot.scatter(x_test[:, 1], y_prediction, color='blue', linewidth=3)
  43. pyplot.xticks(())
  44. pyplot.yticks(())
  45. pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement