'Converting data type of values in a column of dataframe
I have implemented ANN regression on a dataset. The actual values and results are present in a dataframe. I want to calculate bias for each observation. However, the predictions are collected as given below. Consider df (after adding the results i.e., column predicted) is the dataframe that I have been working on for your reference.
import pandas as pd
actual=[[11.4],[32.46],[66.37]]
df = pd.DataFrame(actual,columns=['actual'])
#some code for ann
#following are predictions
predicted=['[11.14]','[33.6]','[66.7]']
df['predicted']=predicted
print(df.info())
x= df['predicted'].values.flatten()
print(x)
print(type(x))
print(type(x[1]))
#bias calculation
#bias= df['actual']-df['predicted']
#print(bias)
following is the out put of above code.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 actual 3 non-null float64
1 predicted 3 non-null object
dtypes: float64(1), object(1)
memory usage: 176.0+ bytes
None
actual predicted
0 11.40 [11.14]
1 32.46 [33.6]
2 66.37 [66.7]
<class 'numpy.ndarray'>
<class 'str'>
Is there any way I can calculate the bias, assuming I have only final dataframe df (i.e., after adding the ann results).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
