ValueError: could not convert string to float: 'critical'
<pre><code>import pandas as pd
from sklearn import  cross_validation
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error

names = ['dyastolic blood pressure','heart rate','pulse oximetry', 'respiratory rate','systolic blood pressure', 'temperature', 'class']
data = pd.read_csv("vitalsign1.csv", names = names)
array = data.values

X = array[:,0:6]

y = array[:,6]
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=.5)

estimator = DecisionTreeRegressor(criterion = "mse", max_leaf_nodes = 6)
estimator.fit(X_train,y_train)
y_pred = estimator.predict(X_test)
score = mean_squared_error(y_test,y_pred)
</code></pre>

<p>For the above code, I am receiving a value error:</p>

<pre><code>ValueError: could not convert a string to float: 'critical'
</code></pre>

<p>which i do understand that on my "class" column i have two class called <code>critical</code> and <code>excellent</code> rather it should have a number such as <code>0</code> and <code>1</code>. but i want to keep the class as it is.</p>

<p>how to solve this? my data looks like this :</p>

<pre><code>115 77  99  18  148 35  critical
99  61  97  14  147 37  excellent
</code></pre>

<p>Add a converter to <code>pandas.read_csv</code> to transform the symbols <code>critical</code> and <code>excellent</code> to <code>0</code> and <code>1</code> respectively.</p>

<p>Something like the following:</p>

<pre><code>&gt;&gt;&gt; data = pd.read_csv(
    "vitalsign1.csv", names=names,
    converters={
        "class": lambda x: dict(critical=0, excellent=1)[x]
        }
    )
</code></pre>

<p>This will result in a dataset like the following:</p>

<pre><code>&gt;&gt;&gt; data
   dyastolic blood pressure  heart rate  pulse oximetry  respiratory rate  systolic blood pressure  temperature  class
0                       115          77              99                18                      148           35      0
1                        99          61              97                14                      147           37      1
</code></pre>

python machine-learning scikit-learn decision-tree