#Xetti reqressiya umumi import matplotlib pyplot as plt



Yüklə 21,49 Kb.
tarix08.12.2022
ölçüsü21,49 Kb.
#73071
Kollokvium-2


#Xetti reqressiya umumi
import matplotlib.pyplot as plt
from scipy import stats
x=[6,8,9,8,3,18,3,10,5,12,13,10,7]
y=[100,87,88,89,112,87,104,88,95,79,78,86,87]
slope, intercept, r, p ,std_err=stats.linregress(x,y)

def myfunc(x):


return slope * x + intercept

model=list(map(myfunc,x))


plt.scatter(x,y)


plt.plot(x,model)
plt.show()

#Korrelyasiya emsali-r


from scipy import stats
x=[6,8,9,8,3,18,3,10,5,12,13,10,7]
y=[100,87,88,89,112,87,104,88,95,79,78,86,87]
slope, intercept, r, p ,std_err=stats.linregress(x,y)
print(r)

#sklearn kitabxanasi


import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv("staj_maas.csv",sep=";")

plt.scatter(df.staj,df.maas)


plt.xlabel("staj")
plt.ylabel("maas")
plt.show()

from sklearn.linear_model import LinearRegression


lr=LinearRegression()
x=df.staj.values.reshape(-1,1)
y=df.maas.values.reshape(-1,1)
lr.fit(x,y)
#y=slope * x + intercept
interc=lr.intercept_
slope+lr.coef_
print("intercept= ",intercept,"slope= ",slope)

#y-i x-e gore texmin etmek mumkundur


print(lr.predict([[10]]))
import numpy as np
import pandas as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
lr=LinearRegression()
x=df.staj.values.reshape(-1,1)
y=df.maas.values.reshape(-1,1)
lr.fit(x,y)
plt.scatter(df.staj,df.maas)
plt.xlabel("staj")
plt.ylabel("maas")
array=np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]).reshape(-1,1)
y_head=lr.predict(array)
plt.plot(array,y_head,color="red")
plt.show()

#Coxsayli xetti reqressiya


import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
df=pd.read_csv("mlr.csv",sep=";")
x=df.iloc[:,[0,2]].values
y=df.maas.values.reshape(-1,1)
mlr=LinearRegression()
mlr.fit(x,y)
print("Intercept= ",mlr.intercept_)
print("Slope= ",mlr.coef_)
print("Mlr= ",mlr.predict([[10,35],[5,35]]))

#Polinom reqressiya


import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
df=pd.read_csv("polynomial_regression.csv",sep=";")
x=df.car_price.values.reshape(-1,1)
y=df.max_speed.values.reshape(-1,1)
plt.ylabel("max_speed")
plt.xlabel("car_prive")
lnr_reg=LinearRegression()
lnr_reg.fit(x,y)
y_head=lnr_reg.predict(x)
plt.scatter(x,y)
plt.plot(x,y_head,color="red")
plt.show()

import numpy as np


import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
df=pd.read_csv("polynomial_regression.csv",sep=";")
x=df.car_price.values.reshape(-1,1)
y=df.max_speed.values.reshape(-1,1)
pol_reg=PolynomialFeatures(degree=2)
x_pol=pol_reg.fit_transform(x)
print(pd.DataFrame(x_pol))
plt.ylabel("max_speed")
plt.xlabel("car_price")
plt.scatter(x,y)
lin_reg2=LinearRegression()
lin_reg2.fit(x_pol,y)
y_head2=lin_reg2.predict(x_pol)
plt.plot(x,y_head2,color="green")
plt.show()

#Decision Tree


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv("dataset.csv",sep=',')
x=df["staj"].values.reshape(-1,1)
y=df["maas"].values.reshape(-1,1)

from sklearn.tree import DecisionTreeRegressor


tree_reg=DecisionTreeRegressor()
tree_reg.fit(x,y)

plt.scatter(x,y,color='red')


x1=np.arange(min(x),max(x),0.01).reshape(-1,1)


y_head=tree_reg.predict(x1)

plt.plot(x1,y_head,color='green')


plt.xlabel('level')
plt.ylabel('price')
plt.show()

import numpy as np


import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

df=pd.read_csv("logistic_regression_classification.csv")


df.drop(["Unnamed:32","id"],axis=1,inplace=True)
df.diagnosis=[1 if each=="M" else 0 for each in df.diagnosis]

y=df.diagnosis.values


x_data=df.drop(["diagnosis"],axis=1)
x=(x_data-np.min(x_data))/(np.max(x_data)-np.min(x_data)).values
x_train,x_test,y_train=train_test_split(x,y,test_size=0.2,random_state=42)

lr=LogisticRegression()


lr.fit(x_train,y_train)
print("test accuracy {}".format(lr.score(x_test,y_test)))
Yüklə 21,49 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin