Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn import svm
- from sklearn.model_selection import train_test_split
- df = pd.DataFrame({'age':[20,30,40,50],
- 'sex':['male','female','female','male'],
- 'region':['northwest','southwest','northeast','southeast'],
- 'charges':[1000,1000,2000,2000]})
- df.sex = (df.sex == 'female')
- df.region = pd.Categorical(df.region)
- df.region = df.region.cat.codes
- X = df.loc[:,['age','sex','region']]
- y = df.loc[:,['charges']]
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
- clf = svm.SVC(C=1.0, cache_size=200,decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf')
- clf.fit(X_train, y_train)
- import pandas as pd
- from sklearn import svm
- from sklearn.model_selection import train_test_split
- df = pd.DataFrame({'age':[20,30,40,50],
- 'sex':['male','female','female','male'],
- 'region':['northwest','southwest','northeast','southeast'],
- 'charges':[1000,1000,2000,2000]})
- df.sex = (df.sex == 'female')
- df = pd.concat([df,pd.get_dummies(df.region)],axis = 1).drop('region',1)
- X = df.drop('charges',1)
- y = df.charges
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
- clf = svm.SVC(C=1.0, cache_size=200,decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf')
- clf.fit(X_train, y_train)
- from sklearn.preprocessing import LabelEncoder
- le = LabelEncoder()
- df.region = le.fit_transform(df.region)
Add Comment
Please, Sign In to add comment