X train, X test, y train, y test = train test split X, y, test size=0




Download 55,53 Kb.
Sana20.12.2023
Hajmi55,53 Kb.
#125137
Bog'liq
ml-3


O‘ZBEKISTON RESPUBLIKASI RAQAMLI TEXNOLOGIYALAR VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

Mashinali o’qitishga kirish


Bajardi: 222-21 guruh talabasi


Abduraxmonov Anvar

TOSHKENT 2023


import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score

# Ma'lumotlar to'plamini yuklash


# CSV faylni o'qish


df = pd.read_csv('data.csv')
# X va y ni ajratib olish
X = df.drop('xulqi', axis=1)
y = df['xulqi']

# Ma'lumotlarni trening va test qismlarga ajratib olish


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# KNN modelini yaratish va o'qitish


knn = KNeighborsClassifier(n_neighbors=3) # N tezlik
knn.fit(X_train, y_train)

# Test qismi uchun taxmin qilish


y_pred = knn.predict(X_test)

# Natijalarni baholash


accuracy = accuracy_score(y_test, y_pred)
print(f"Aniqlik: {accuracy}")

# Grafikni chiqarish


fig, ax = plt.subplots()

# O'zgaruvchilarni o'zgartiring, agar x va y larni o'zgartirmoqchi bo'lsangiz


x = df['o`rtacha_baholari']
y = df['sinfi']

# Joriy va to'g'ri natijalarni vizualizatsiya qilish


ax.scatter(x[y == 0], y[y == 0], color='red', label='Xulqi=0')
ax.scatter(x[y == 1], y[y == 1], color='blue', label='Xulqi=1')

ax.set_xlabel('O`rtacha Baholari')


ax.set_ylabel('Sinfi')
ax.legend()
plt.show()

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

# Ma'lumotlar to'plamini yuklash


# CSV faylni o'qish


df = pd.read_csv('data.csv')
# X va y ni ajratib olish
X = df.drop('xulqi', axis=1)
y = df['xulqi']

# Ma'lumotlarni trening va test qismlarga ajratib olish


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# KNN modelini yaratish va o'qitish


cvm = SVC(kernel='linear',C=1) # N tezlik
cvm.fit(X_train, y_train)

# Test qismi uchun taxmin qilish


y_pred = cvm.predict(X_test)

# Natijalarni baholash


accuracy = accuracy_score(y_test, y_pred)
print(f"Aniqlik: {accuracy}")

# Grafikni chiqarish


fig, ax = plt.subplots()

# O'zgaruvchilarni o'zgartiring, agar x va y larni o'zgartirmoqchi bo'lsangiz


x = df['o`rtacha_baholari']
y = df['sinfi']

# Joriy va to'g'ri natijalarni vizualizatsiya qilish


ax.scatter(x[y == 0], y[y == 0], color='red', label='Xulqi=0')
ax.scatter(x[y == 1], y[y == 1], color='blue', label='Xulqi=1')

ax.set_xlabel('O`rtacha Baholari')


ax.set_ylabel('Sinfi')
ax.legend()
plt.title('CVM')
plt.show()


Download 55,53 Kb.




Download 55,53 Kb.

Bosh sahifa
Aloqalar

    Bosh sahifa



X train, X test, y train, y test = train test split X, y, test size=0

Download 55,53 Kb.