python - Function to run ANOVA and give F stat values as the output
问题描述
The function im trying to write would take the dataframe provided and calculate the F statistic values and provide those as the output.
Data Format
Final
Color Strength Fabric Sales
0 1 1 10
1 2 2 15
Here Color, strength and Fabric are independent while Sales is dependent.
def regression():
X=Final.copy()
y=Final[['Sales']].copy()
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=.2, random_state=0)
sel=f_classif(X_train, y_train)
p_values=pd.Series(sel[0], index=X_train.columns)
p_values=p_values.reset_index()
pd.options.display.float_format = "{:,.2f}".format
return p_values
Final.apply(regression)
This is the code I came up with but its throwing an error
TypeError: regression() takes 0 positional arguments but 1 was given
What could be going wrong with this code?
解决方案
When you use .apply()
, the dataframe or series is passed as an argument to the function you call. The documentation explains it more. In order to fix this, instead of:
Final.apply(regression)
You can simply call regression()
like this:
m_p_values = regression()
And now the variable m_p_values
contains the return value of regression()
.
推荐阅读
- reactjs - 在不使用 react-apollo 的情况下应用 appsync 订阅的优化方法是什么?
- linux - SSH 后 shell 脚本停止(登录到 kubernetes pod)
- android - 对“jniRegisterNativeMethods”Android NDK 的未定义引用
- ruby-on-rails - NoMethodError(nil:NilClass 的未定义方法 `posts'):
- mysql - 姜戈。我如何获得重复的用户列表?
- javascript - 如何调用一组对象中同一列的属性?(Node.js)
- ios - 协议实现方法不在 Swift 中调用
- shell - 通过子字符串查找并打开文件夹
- qa - 如何找出我对 yandex.tank 弹药的 POST 请求的大小?
- javascript - 如何获取 recaptcha 值以便可以在条件检查中使用