You could argue that it should be set to 0 - but electric cars cannot produce sulfur dioxide. Consider situtations when imputation doesn't make sense.Ĭonsider a dataset with rows of cars ("Danho Diesel", "Estal Electric", "Hesproc Hybrid") and columns with their properties (Weight, Top speed, Acceleration, Power output, Sulfur Dioxide Emission, Range).Įlectric cars do not produce exhaust fumes - so the Sulfur dioxide emission of the Estal Electric should be a NaN-value (missing). If imputation doesn't make sense, don't do it. XGBoost can.Īs mentioned in this article, scikit-learn's decision trees and KNN algorithms are not ( yet) robust enough to work with missing values. Scitkit-learn's models cannot handle missing values. In these cases you should use a model that can handle missing values. If you can get those predictions going using the RandomForestClassifier, you can then run the confusion matrix code above on the results.Sometimes missing values are simply not applicable. The top it looks like this (click on picture to enlarge): I basically use the minimum and maximum values of the target variable to set a range, then aim for 10 different classes of temperature and create a new column in the table which assign that class to each row. I have done a quick and dirty conversion on the same data linked in that article, check it out here. You could say transform the target temperature to be a new_target_class, then change your code to use the. You could consider altering your task to make it be a classification problem, for example by grouping the temperatures in to classes of a given range. In general, if you do have a classification task, printing the confusion matrix is a simple as using the _matrix function.Īs input it takes your predictions and the correct values: from trics import confusion_matrixĬonf_mat = confusion_matrix(labels, predictions) Your problem (as the author in your link states) is a regression problem, because you are predicting a continuous variable (temperature). This is because it shows how well a model is classifying samples i.e. The following error appears:įrom the code and task as your present it, a confusion matrix wouldn't make sense. So my question is: how can I add a Confusion matrix to measure accuracy? I tried this example from this here, but it doesn't work. (graph, ) = aph_from_dot_file('tree.dot') Įxport_graphviz(tree, out_file = 'tree.dot', feature_names = feature_list, rounded = True, precision = 1) # Sort the feature importances by most important firstįeature_importances = sorted(feature_importances, key = lambda x: x, reverse = True) # List of tuples with variable and importanceįeature_importances = Importances = list(rf.feature_importances_) # Calculate mean absolute percentage error (MAPE) Print('Promedio del error absoluto:', round(np.mean(errors), 2), ' Porcentaje.') # Print out the mean absolute error (mae) # Use the forest's predict method on the test data Rf = RandomForestRegressor(n_estimators = 1000, random_state = 42) # Instantiate model with 1000 decision trees Print('Error: ', round(np.mean(baseline_errors), 2)) # Baseline errors, and display average baseline errorīaseline_errors = abs(baseline_preds - test_labels) ![]() Train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size = 0.25, random_state = 42)īaseline_preds = test_features # Split the data into training and testing sets # Labels are the values we want to predictįeatures= features.drop('target', axis = 1) Os.environ += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'įeatures = pd.read_csv('prueba2.csv',sep=' ') # Using Skicit-learn to split data into training and testing setsįrom sklearn.model_selection import train_test_splitįrom sklearn.ensemble import RandomForestRegressor import pandas as pdįrom sklearn.preprocessing import LabelEncoderįrom sklearn.ensemble import RandomForestClassifierįrom sklearn.ensemble import GradientBoostingClassifier The example I took from this article here. I applied this random forest algorithm to predict a specific crime type.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |