我有一个适合数据集中各列的模型。因此,对于每一列,它都在创建一个预测值。我想以如下方式打印这些预测值: 到目前为止,我只设法获得了这种输出: 这就是我的代码现在的样子: **编辑:
我的数据结构看起来像这样: CubicSpline是我用来拟合模型的函数,用于在自变量的任何给定值下预测每一列的值。它是scipy.interpolate库的一部分。基本上,我已将此代码设置为允许用户输入自变量的任何值(在这种情况下为80),并且该代码将适合模型并为该值的所有列生成一个预测值。这些预测本身运行良好。我只需要将它们与列名和预测值并排输出。 关于如何调整打印输出方式以达到所需格式的任何建议?我尝试了各种使用数据框和列表元组的方法,但是要么不断出错,要么只是保持已经拥有的格式。 谢谢!columnname1: prediction1, columnname2: prediction2, ...
'columnname1': array(prediction1), 'columnname2': array(prediction2), ...
#Create a list of column names
colnames = list(data)
colcount = len(data.columns)
#Initialize empty variables
cs = {}
predicted = {}
#Make a function to enter user-defined independent variable value
def fit1 (indepvar):
for i in colnames:
cs[i] = CubicSpline(data["IndependentVariable"],data[i])
#print(cs[i](indepvar))
predicted[i]=cs[i](indepvar)
return;
#Enter desired independent variable value to generate predictions
indepvar=80
fit1(indepvar)
predicted['IndependentVariable']=indepvar
print(predicted)
IndependentVariable Col1 Col2 Col3 ...
50 .74 1 1 ...
100 0 .23 1 ...
...
0 个答案:
没有答案