-
Notifications
You must be signed in to change notification settings - Fork 0
/
servoprediction.py
98 lines (54 loc) · 1.68 KB
/
servoprediction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""ServoPrediction.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1lBICidYiX7vbXBoWcry4qjGiuUcimWAD
# **SERVO PREDICTION WITH LINEAR REGRESSION **
DATA SOURCE:'https://github.com/YBIFoundation/Dataset/raw/main/Servo%20Mechanism.csv
**IMPORT LIBRARY**
"""
import pandas as pd
import numpy as np
"""**IMPORT DATA**"""
servo=pd.read_csv('https://github.com/YBIFoundation/Dataset/raw/main/Servo%20Mechanism.csv')
"""**DESCRIBE DATA**"""
servo.head()
servo.info()
servo.describe()
"""**DATA VISUALIZATION**"""
servo.columns
servo.shape
servo['Motor'].value_counts()
servo['Screw'].value_counts()
servo.replace({'Motor':{'A':0,'B':1,'C':2,'D':3,'E':4}},inplace=True)
servo.replace({'Screw':{'A':0,'B':1,'C':2,'D':3,'E':4}},inplace=True)
y=servo['Class']
y.shape
y
X=servo[['Motor', 'Screw','Pgain', 'Vgain']]
X=servo.drop(['Class'],axis=1)
X
X.shape
"""**Train Test Split**"""
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=2529)
X_train.shape,X_test.shape,y_train.shape,y_test.shape
"""**Modeling**"""
from sklearn.linear_model import LinearRegression
lr=LinearRegression()
lr.fit(X_train,y_train)
"""**Prediction**"""
y_pred=lr.predict(X_test)
y_pred.shape
y_pred
"""Model Evaluation"""
from sklearn.metrics import mean_squared_error,mean_absolute_error,r2_score
mean_squared_error(y_test,y_pred)
mean_absolute_error(y_test,y_pred)
r2_score(y_test,y_pred)
import matplotlib.pyplot as plt
plt.scatter(y_test,y_pred)
plt.xlabel('Actual')
plt.ylabel('Predicted')
plt.title("Actual vs Predicted")
plt.show()