我正在学习python2.7.13在windows上的类构造。我得到一个错误:Sales实例没有属性\uuu float\u
有什么提示可以让我的代码工作吗?如何避免这种错误? 下面是我的代码
class Sales():
# Sales predicts
def __init__(self, df):
# Each sales dataset has descriptive statistics.
self.desc = df.describe()
self.rows = len(df)
self.cols = len(df.columns)
self.counts = df['TARGET'].value_counts()
self.plot = sns.countplot(x = 'TARGET', data = df, palette='hls')
def sales_prob(self, df1, df2):
"""
Function that computes logistic regression given a training and testing dataframes
:param df1: historical dataframe (training)
:param df2: monthly dataframe (testing)
:return: df_out : dataframe containing predictions for the target 2
"""
X_train0 = list(df1.loc[:, df1.columns != 'TARGET'])
X_train = df1[X_train0]
y_train = df1[['TARGET']]
X_test0 = list(df2.loc[:, df2.columns != 'TARGET'])
X_test = df2[X_test0]
y_test = df2[['TARGET']]
classifier = LogisticRegression(random_state=0)
classifier.fit(self, X_train, y_train.values.ravel())
y_pred2 =pd.DataFrame(classifier.predict_proba(self, X_test))
y_pred2['prediction2'] = y_pred2[[2]]
df_out = pd.merge(df2, y_pred2[['prediction2']], how = 'left', left_index=True, right_index=True)
return (df_out)
# Example to use Sales class
venta = Sales(data1)
venta.desc
venta.cols
proba = venta.sales_prob(data1, data2)
这是我的回溯
Traceback (most recent call last): File "C:\Documents\Anaconda2\Lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in proba = venta.sales_prob(data1, data2) File "", line 29, in sales_prob classifier.fit(self, X_train, y_train.values.ravel()) File "C:\Documents\Anaconda2\Lib\site-packages\sklearn\linear_model\logistic.py", line 1173, in fit order="C") File "C:\Documents\Anaconda2\Lib\site-packages\sklearn\utils\validation.py", line 521, in check_X_y ensure_min_features, warn_on_dtype, estimator) File "C:\Documents\Anaconda2\Lib\site-packages\sklearn\utils\validation.py", line 382, in check_array array = np.array(array, dtype=dtype, order=order, copy=copy) AttributeError: Sales instance has no attribute 'float' traceback.print_tb
目前没有回答
相关问题 更多 >
编程相关推荐