Вам нужны фиксированные метки от строкового значения до целого числа:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD'))
#fixed labels
df['sex'] = [np.random.choice(['0', '1']) for x in range(len(df))]
df['weight'] = [np.random.choice(list(range(4))) for x in range(len(df))]
% matplotlib inline
from pandas import read_csv, DataFrame
from sklearn.linear_model import LinearRegression, LogisticRegression
from sklearn.svm import SVR
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.cross_validation import train_test_split
import matplotlib.pyplot as plt
trg = df[['sex','weight']]
trn = df.drop(['sex','weight'], axis=1)
#list of different models
models = [LinearRegression(),
RandomForestRegressor(n_estimators=100, max_features ='sqrt'),
SVR(kernel='linear'),
LogisticRegression()
]
Xtrn, Xtest, Ytrn, Ytest = train_test_split(trn, trg, test_size=0.4)
TestModels = DataFrame()
tmp = {}
#for each model in list
for model in models:
#get name
m = str(model)
tmp['Model'] = m[:m.index('(')]
#for each columns from result list
for i in range(Ytrn.shape[1]):
#learning model
model.fit(Xtrn, Ytrn.iloc[:,i])
#calculate coefficient of determination
tmp['R2_Y%s'%str(i+1)] = r2_score(Ytest.iloc[:,0], model.predict(Xtest))
#write data and final datarame
TestModels = TestModels.append([tmp])
#make an index by model name
TestModels.set_index('Model', inplace=True)
fig, axes = plt.subplots(ncols=2, figsize=(10,4))
TestModels.R2_Y1.plot(ax=axes[0], kind='bar', title='R2_Y1')
TestModels.R2_Y2.plot(ax=axes[1], kind='bar', color='green', title='R2_Y2')