簡體   English   中英

訓練 model 時我做錯了什么?

[英]What am I doing wrong when training a model?

我解決了以下問題:`

我們已經收集了更多關於貓和狗的數據,並准備訓練我們的機器人對它們進行分類! 下載訓練數據集https://stepik.org/media/attachments/course/4852/dogs_n_cats.csv並在其上訓練決策樹。 之后,從作業中下載數據集並預測哪些觀察屬於誰。 在數據集中輸入狗的數量。 作業中允許出現某種錯誤。

我訓練了 model:

import sklearn
import pandas as pd
import numpy as nm
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import tree
from sklearn.model_selection import train_test_split, cross_val_score

df = pd.read_csv('dogs_n_cats.csv')

X = df.drop(['Вид', 'Шерстист'], axis=1)
y = df['Вид']

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.67, random_state=42)

clf = tree.DecisionTreeClassifier(criterion='entropy', max_depth=4)
clf.fit(X_train, y_train)

之后,我從任務https://stepik.org/api/attempts/540562013/file下載數據集並開始確定數據集中的狗數量:

df2 = pd.read_json('we.txt')

X2 = df.drop(['Вид', 'Шерстист'], axis=1)
y2 = df['Вид']
X_train2, X_test2, y_train2, y_test2 = train_test_split(X, y, train_size=0.67, random_state=42)

df2_predict = clf.predict(X2)
l = list(df2_predict)
l.count('собачка')

任務中狗的數量應該是 49,但在執行 l.count ('dog') 后我得到 500。訓練 model 時我做錯了什么?

這似乎是一個錯字。 在您的代碼段中,您使用第一個 dataframe 創建X2

我無法訪問第二個文件,但更改這一行應該可以解決問題:

X2 = df.drop(['Вид', 'Шерстист'], axis=1)
-->
X2 = df2.drop(['Вид', 'Шерстист'], axis=1)

除此之外,您已經獲得了訓練集和測試集,因此不需要調用train_test_split

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM