我试图将两个 csv 文件导入df1
和df2
. 将它们连接起来制作df3
. 我试图打电话给mutual_info_regression
他们,但我得到一个值错误ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required
。我检查了X
、y
和的尺寸discrete_features
。他们似乎都还好。
由于代码适用于其他csv
文件(我已经测试过),我认为问题出在我的csv
文件而不是代码上。
import numpy as np
import pandas as pd
df1 = pd.read_csv("WT_MDE.csv", index_col=0)
df1["Interact"] = 1
df2 = pd.read_csv("M_MDE.csv", index_col=0)
df2["Interact"] = 0
data = pd.concat([df1, df2])
X = data.copy()
y = X.pop("Interact")
discrete_features = X.dtypes == float
from sklearn.feature_selection import mutual_info_regression
def make_mi_scores(X, y, discrete_features):
mi_scores = mutual_info_regression(X, y, discrete_features = discrete_features)
mi_scores = pd.Series(mi_scores, name="MI Scores", index=X.columns)
mi_scores = mi_scores.sort_values(ascending=False)
return mi_scores
mi_scores = make_mi_scores(X, y, discrete_features)
如果有人可以提供帮助,我将不胜感激。