-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPredictor.py
189 lines (133 loc) · 5.34 KB
/
Predictor.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: utf-8 -*-
"""project1
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1JKalG1fiTa7i7JpKpz2907BgtJ2roAK2
"""
from google.colab import drive
drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
# read CSV file into a pandas DataFrame
df = pd.read_csv("/content/drive/MyDrive/mini_project/pushup_count1.csv")
# plot the data as a scatter plot
df.plot(kind="scatter", x="Age", y="Push up counted", c="green")
# set plot title and axis labels
plt.title("Scatter Plot")
plt.xlabel("Age")
plt.ylabel("Push up counted")
# display plot
plt.show()
import pandas as pd
data = pd.read_csv("/content/drive/MyDrive/mini_project/pushup_count1.csv")
X = data.drop("Age", axis=1)
y = data["Push up counted"]
#Splitting
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
#Train
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train, y_train)
from sklearn.metrics import accuracy_score
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
# Load the dataset from CSV file
data = pd.read_csv('/content/drive/MyDrive/mini_project/pushup_count1.csv')
# Extract the features (age) and labels (push-up count)
X = data.iloc[:, :-1].values
y = data.iloc[:, 1].values
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Train the linear regression model on the training set
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Predict the push-up counts for the test set
y_pred = regressor.predict(X_test)
# Evaluate the accuracy of the model using mean squared error
mse = mean_squared_error(y_test, y_pred)
print("Mean squared error:", mse)
# Use the trained model to predict the number of push-ups for a person of age 20
age = 14
pushups = regressor.predict([[age]])
print("A person of age", age, "can do", int(pushups), "push-ups.")
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
# Load the dataset from CSV file
data = pd.read_csv('/content/drive/MyDrive/mini_project/pushup_count1.csv')
# Extract the features (age) and labels (push-up count)
X = data.iloc[:, :-1].values
y = data.iloc[:, 1].values
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
# Train the linear regression model on the training set
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Predict the push-up counts for the test set
y_pred = regressor.predict(X_test)
# Evaluate the accuracy of the model using mean squared error
mse = mean_squared_error(y_test, y_pred)
print("Mean squared error:", mse)
# Use the trained model to predict the number of push-ups for a person of age 20
age = 18
pushups = regressor.predict([[age]])
print("A person of age", age, "can do", int(pushups), "push-ups.")
if(age>=10 and age<=15):
print("Standard number is: 8")
elif(age>=16 and age<=20):
print("Standard number is: 12")
elif(age>=21 and age<=25):
print("Standard number is: 20")
elif(age>=26 and age<=30):
print("Standard number is: 24")
elif(age>=31 and age<=40):
print("Standard number is: 28")
else:
print(1)
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
# Load the CSV file into a Pandas DataFrame
df = pd.read_csv('/content/drive/MyDrive/mini_project/pushup_count1.csv')
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(df.drop('Push up counted', axis=1), df['Age'], test_size=0.2, random_state=42)
# Train a random forest classifier on the training set
rf = RandomForestClassifier(n_estimators=100, random_state=42)
rf.fit(X_train, y_train)
# Make predictions on the testing set
y_pred = rf.predict(X_test)
# Calculate accuracy
accuracy = 100*accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
data = pd.read_csv("/content/drive/MyDrive/mini_project/pushup_count1.csv")
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
regressor=LinearRegression()
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print("Mean squared error:", mse)
age = int(input('enter age='))
pushups = regressor.predict([[age]])
print("A person of age", age, "can do", int(pushups), "push-ups.")