SHARE
TWEET

Untitled

a guest Jul 24th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top