Created
September 10, 2018 14:51
-
-
Save emmagrimaldi/0d813e5494a2d587572869ef584d6d4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.tree import DecisionTreeClassifier | |
| import pandas as pd | |
| # create a matrix including the data | |
| data = [[8,8,'dog'],[50,40,'dog'],[8,9,'cat'],[15,12,'dog'],[9,9.8,'cat']] | |
| # generating a dataframe from the matrix | |
| df = pd.DataFrame(data, columns = ['weight','height','label']) | |
| # defining predictors | |
| X = df[['weight','height']] | |
| # definig the target variable and mapping it to 1 for dog and 0 for cat | |
| y = df['label'].replace({'dog':1, 'cat':0}) | |
| # instantiating the model | |
| tree = DecisionTreeClassifier() | |
| # fitting the model | |
| model = tree.fit(X,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment