import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import PolynomialFeatures
path=r"C:\Users\venkatesh\Desktop\pandasimpor\T11.csv"
df=pd.read_csv(path)
df.head(500)
x=df[['Wind Speed (m/s)']]
y=df[['LV ActivePower (kW)']]
lm=LinearRegression()
cost=np.array(cost)
degree=np.array(degree)
plt.scatter(degree,cost)
plt.title("degree vs Mean Square Error")
plt.xlabel("degree")
plt.ylabel("Mean Sqaure Error")
cost=[]
degree=[]
for i in range(30):
poly_reg=PolynomialFeatures(degree=i)
input_reg=poly_reg.fit_transform(x)
lm.fit(input_reg,y)
p=lm.predict(input_reg)
cost.append(mean_squared_error(p,y))
degree.append(i)
print(i)
print(" ")
print(mean_squared_error(p,y))
plt.scatter(x,y)
plt.scatter(x,p,color='r')
plt.xlabel('Input')
plt.ylabel('output')
plt.show()
cost=np.array(cost)
cost.min()
poly_reg=PolynomialFeatures(degree=14)
input_reg=poly_reg.fit_transform(x)
lm.fit(input_reg,y)
p=lm.predict(input_reg)
print(' ')
print(mean_squared_error(p,y))
plt.scatter(x,y)
plt.scatter(x,p,color='r')
plt.xlabel('Input')
plt.ylabel('output')
plt.show()
path=r"C:\Users\venkatesh\Desktop\pandasimpor\T11.csv"
df1=pd.read_csv(path)
df1=df1.iloc[18073:18444,:-1]
df1
df1
x_test=df1[['Wind Speed (m/s)']]
xx=df1[['Wind Speed (m/s)']]
y_test=df1[['LV ActivePower (kW)']]
x_test=poly_reg.fit_transform(x_test)
y_output=lm.predict(x_test)
print(mean_squared_error(y_output,y_test))
plt.scatter(xx,y_output)
plt.xlabel(' Input')
plt.ylabel('Polynomial Regression Based output')
plt.show()
plt.scatter(xx,y_test,color='r')
plt.xlabel('Input')
plt.ylabel('output')
plt.show()