pandas
数据中有一列为Body ID 代表,这个dataFrame对应id的文本。下面的代码,解决的是如何把Body ID对应列的id替换成文本。
import numpy as np,pandas as pd
df_val = pd.read_csv('validation_data_cx.csv',encoding = 'utf-8')
df_val.head(3)
df_val.to_csv('validataon_data_cx.csv',encoding = 'utf-8')
def mergedata(df):
df_train2 = df.sort_values(["Body ID"],ascending=True)
del df['Body ID']
del df['Stance']
df_merge = df.merge(df_train2, left_on='ID', right_on='Body ID', how='inner')
del df_merge['ID_x']
return df_merge
merge_val = mergedata(df_val)
merge_val.to_csv('val_merge.csv',encoding = 'utf-8',index = None)
### 按照ID_y重排dataframe
df_testM = merge_val.sort_values(["ID_y"],ascending=True)
keras
sample_weight
唉,coding能力太渣渣了。网上大多是class_weight的例子。对于one_hot输出的不适用。费了老大的劲找到一个sample_weight的例子。好好珍惜
sample_weight例子
问题本身
代码错误
TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64
leaks_dense = Dense(num_dense/2, activation=act)(leaks_input)
原本以为是需要指定这一层的数据类型,改了好几遍都不对。
正确的改法 num_dense//2
参考地址
In Python 2.X:
>>> 10/3
3
>>> # to get a floating point number from integer division:
>>> 10.0/3
3.3333333333333335
>>> float(10)/3
3.3333333333333335
In Python 3:
>>> 10/3
3.3333333333333335
>>> 10//3
3