我的帖子怎么没人看呢,伤心,我这个警告是什么意思啊,要怎么修改啊
警告什么意思要怎么修改{:9_234:}Warning (from warnings module):
File "C:\Users\zmj佳佳佳\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\model_selection\_split.py", line 665
warnings.warn(("The least populated class in y has only %d"
UserWarning: The least populated class in y has only 1 members, which is less than n_splits=2.
代码
import pandas as pd #导入数据集
url=r"C:\Users\zmj佳佳佳\Desktop\第六步离散化测试.csv"
df = pd.read_csv(url, header = None,low_memory=False)#将数据集分为训练集和测试集
df.columns=["sub_grade","dti","delinq_2yrs","earliest_cr_line","fico_range_low","inq_last_6mths",
"mths_since_last_delinq","pub_rec","revol_bal","revol_util","mths_since_last_major_derog",
"tot_cur_bal","open_acc_6m","open_il_12m","open_il_24m","mths_since_rcnt_il","open_rv_12m",
"open_rv_24m","max_bal_bc","all_util","inq_last_12m","acc_open_past_24mths","avg_cur_bal",
"bc_open_to_buy","mo_sin_old_il_acct","mo_sin_old_rev_tl_op","mo_sin_rcnt_rev_tl_op","mo_sin_rcnt_tl",
"mort_acc","mths_since_recent_bc_dlq","mths_since_recent_inq","mths_since_recent_revol_delinq",
"num_accts_ever_120_pd","num_actv_bc_tl","num_actv_rev_tl","num_bc_sats","num_bc_tl",
"num_rev_accts","num_rev_tl_bal_gt_0","num_tl_90g_dpd_24m","num_tl_op_past_12m","pct_tl_nvr_dlq",
"pub_rec_bankruptcies"]
#将数据集分为训练集和测试集
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
x, y = df.iloc[:, 1:].values, df.iloc[:, 0].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 0)
feat_labels = df.columns
forest = RandomForestClassifier()
forest.fit(x_train, y_train)
param={"n_estimators":,"max_depth":}
#网格搜索与交叉验证
gc=GridSearchCV(forest,param_grid=param,cv=2)
gc.fit(x_train,y_train)
print("准确率:",gc.score(x_test,y_test))
print("查看选择的参数模型:",gc.best_params_)
#特征重要性评估
import numpy as np
importances = forest.feature_importances_
indices = np.argsort(importances)[::-1]
for f in range(x_train.shape):
print("%2d) %-*s %f" % (f + 1, 30, feat_labels], importances])) 涉及pandasnumpy 的一般专业性都很强
可以说,一般人都不会太深研究 wp231957 发表于 2020-4-8 20:18
涉及pandasnumpy 的一般专业性都很强
可以说,一般人都不会太深研究
{:5_99:} 嘴角向上 发表于 2020-4-8 20:20
你这是不是还涉及到人工智能还是机器学习呀
就更专业了,百度吧,度娘还是比较强的 很多人都看到你的帖子了。
之所以没人回答,我认为原因有两点
1、你的代码太乱了。看起来眼花缭乱的,很多人不愿意去仔细看。
2、愿意看的那些人,可能也不知道怎么回答。
请重新编辑一下帖子,把代码放到代码编辑器中。
发帖的时候在编辑框上方工具栏,有个"<>"是专门发代码用的。
发出来的代码看上去比较整洁,而且也方便其他人复制
代码发出来应该是这个样子的 因为你这出错不是python出错,而是你的机器学习的库报的错,对于以学习python为主的论坛太过偏门。
报错直译是:y中最小构成类的成员只有1位,少于n_splits=2要求的2位。
应该是这句报错:
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, random_state = 0)
你看看y的取值是不是有问题,别的我也帮不了什么了。 txxcat 发表于 2020-4-8 20:39
因为你这出错不是python出错,而是你的机器学习的库报的错,对于以学习python为主的论坛太过偏门。
报错直 ...
嗯嗯,好的谢谢 sunrise085 发表于 2020-4-8 20:23
很多人都看到你的帖子了。
之所以没人回答,我认为原因有两点
1、你的代码太乱了。看起来眼花缭乱的,很 ...
好的,谢谢 忘了说,去CSDN问问,那里专业人士多一些。
页:
[1]