Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Fri Jul 12 19:10:27 2019
- @author: nodeflux
- """
- import numpy
- import pandas
- from matplotlib import pyplot
- from sklearn.model_selection import train_test_split
- from sklearn.linear_model import LinearRegression
- from sklearn.metrics import mean_squared_error, r2_score
- dataset = pandas.read_csv('/home/nodeflux/Documents/mercubuana/UAS_DATA_MINING/data.csv')
- x = dataset.iloc[:, :-1].values
- y = dataset.iloc[:, 2]
- x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=0)
- regressor = LinearRegression()
- regressor.fit(x_train, y_train)
- y_prediction = regressor.predict(x_test)
- # Coefficient
- print('Coefficient: \n', regressor.coef_)
- # Mean Squared Error
- print("Mean squared error: %.2f" % mean_squared_error(y_test, y_prediction))
- # Variance score
- print("Variance score: %.2f" % r2_score(y_test, y_prediction))
- pyplot.scatter(x_test[:, 0], y_test, color='black')
- pyplot.scatter(x_test[:, 0], y_prediction, color='blue', linewidth=3)
- pyplot.xticks(())
- pyplot.yticks(())
- pyplot.show()
- pyplot.scatter(x_test[:, 1], y_test, color='black')
- pyplot.scatter(x_test[:, 1], y_prediction, color='blue', linewidth=3)
- pyplot.xticks(())
- pyplot.yticks(())
- pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement