Question

Python , I need to Implement a Random Forest Classification Model in Python from any open...

Python , I need to Implement a Random Forest Classification Model in Python from any open dataset available online

Homework Answers

Answer #1

#Text code

# importing the libraries

import pandas as pd

from sklearn.metrics import accuracy_score

# reading csv file "heart.csv"

# file source: https://www.kaggle.com/ronitf/heart-disease-uci#heart.csv

dataset = pd.read_csv("heart.csv")



# extracting features

# “iloc” in pandas is used to select rows and columns by number

X = dataset.iloc[:, :-1]

y = dataset.iloc[:, -1]

# Splitting the dataset into the Training set and Test set

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling

from sklearn.preprocessing import StandardScaler

# Scale X object

sc_X = StandardScaler()

X_train = sc_X.fit_transform(X_train)

X_test = sc_X.fit_transform(X_test)

# Fitting Random Forest Classification to the Training set

from sklearn.ensemble import RandomForestClassifier

random_forest_classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)

random_forest_classifier.fit(X_train, y_train)

# Predicting the Test set results

y_pred_random_forest = random_forest_classifier.predict(X_test)

# finding percentage accuracy

print(accuracy_score(y_test, y_pred_random_forest))

# Output: 0.8688524590163934

#CODE SCREENSHOT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I need to find a random api, use it on python to pull requests. First I...
I need to find a random api, use it on python to pull requests. First I need to present all the information of the api and then play with it while giving examples. The most important step is that I need to make a request to that api and use the data from that request to make additional requests. For example using a tv shows api, requesting the id of a show from the api then using that id for...
Hello Everyone, I need to write a Python code for AES encryption and decryption for any...
Hello Everyone, I need to write a Python code for AES encryption and decryption for any text entered by the user. Can anyone please help me out with it? Thank you so much.
Please design and implement a program using python subtract an input image from another input image....
Please design and implement a program using python subtract an input image from another input image. Please do not use any image processing library functions.
I have the below homework problem for a python programming class, and i really need some...
I have the below homework problem for a python programming class, and i really need some help!! First, take a set of 6 grades from a user and average them. Provide the average to the user. You need to check to make sure the grades are within the normal range. If the grade is less than 0 or more than 100, issue a warning to the user. You don't need to take the grade again, just let the user know....
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was...
I am working on exercise 5.30 from Introduction to Computing using python (Author: Perkovic). I was looking at the solution and was able to understand what to do. However, when I implement the temp function as indicated, I keep getting this error "ValueError: the first two maketrans arguments must have equal length". However, it seems my two arguments are equal length, so I'm not sure what I am doing wrong! print('Exercise 5.30') def many(file): infile = open(file) content = infile.read()...
ASAP I need this code... Design and implement in Python language, a program that calculates the...
ASAP I need this code... Design and implement in Python language, a program that calculates the molecular weight of a formula. Your program should accept a formula in whatever form you choose as input from the user, and should display the molecular weight for that formula. Your program must be able to handle formulas that: consist of a single element, e.g., He    (worth 40 points) consist of a sequence of elements, e.g., H H O    (worth 20 points) contain numeric constants, e.g.,...
I NEED A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX, if we have an DB...
I NEED A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX, if we have an DB file has a records of students number and names like this (Student file) stNum**stName 1 jack 2 maya 3 sam 4 alex 5 jane . . . . . . this file may have a thousands records, if we want to search for a specific record(student), we need to find it by (Index file), in this index file we have this (Index file) stNum**Address...
Python problem: write a main function that ask user for 2 file name, open files and...
Python problem: write a main function that ask user for 2 file name, open files and read the 1st line of each and compare them using hamming function(below is the hamming function I wrote). Just assume the fist line of each file only contains 0s and 1s, such as 0100111101. The main function may have to do some extra work to remove newline characters or other whitespace from the text read from each file. This is hamming function that need...
P(Employed)= 4,125,864. P(Unemployed)= 43,564. If I were to select a random person from the dataset, what...
P(Employed)= 4,125,864. P(Unemployed)= 43,564. If I were to select a random person from the dataset, what is the probability that person is either employed or unemployed?
PYTHON: Write a function called keepShouting. This function does not need any input parameters. The function...
PYTHON: Write a function called keepShouting. This function does not need any input parameters. The function should simply repeat whatever the user enters but in all capitals! The function should ask the user to enter a phrase. The phrase then should be capitalized and printed to the screen. If the user just hits return (which will produce the empty string) then the program should stop. Hint: Use a while loop and string methods # keepShouting() """ The function call should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT