You are on page 1of 5

RIANO, Francis Anthony M APPLIED DATA SCIENCE

WORKSHEET 3.8: SUPERVISED LEARNING IN PYTHON

1 Date:
Import house-votes-84 (edited).csv. Write codes necessary to import and examine this dataset. Which of the
following statements is not true? The target variable in this DataFrame is ‘party’.
A. The DataFrame has a total of 232 rows and 17 columns.
B. Except for party, all of the columns are of type int64.
C. The first row of the DataFrame consists of votes by a Democrat and the second row consists of votes by a A
Republican.
D. There are 17 predictor variables, or features, in this DataFrame.
Output

This study source was downloaded by 100000857417487 from CourseHero.comPage 1 of 5


on 04-19-2023 08:41:52 GMT -05:00

https://www.coursehero.com/file/89946279/DS100-3-WS38pdf/
RIANO, Francis Anthony M APPLIED DATA SCIENCE

WORKSHEET 3.8: SUPERVISED LEARNING IN PYTHON

2 Date:
Perform graphical exploratory data analysis on the house votes dataset. Use Seaborn’s countplot to visualize the votes to the
satellite testing bill, grouped by party. Include the following line before the show function: plt.xticks([0,1], [‘No’,
‘Yes’]). Do the same for the missile bill. Of the two bills, which one/s do Democrats vote resoundingly in favor of, compared
to Republicans?
A. Missile bill
B. Satellite bill
C
C. Both Missile and Satellite bills
D. Neither Missile nor Satellite bill
Output

This study source was downloaded by 100000857417487 from CourseHero.comPage 2 of 5


on 04-19-2023 08:41:52 GMT -05:00

https://www.coursehero.com/file/89946279/DS100-3-WS38pdf/
RIANO, Francis Anthony M APPLIED DATA SCIENCE

WORKSHEET 3.8: SUPERVISED LEARNING IN PYTHON

3 Date:
Predict the party affiliation of the House member whose votes have been recorded in the file named x_new.csv. Write the
code here to achieve the following output:
Party Prediction: [‘democrat’/’republican’]
Code

Output

This study source was downloaded by 100000857417487 from CourseHero.comPage 3 of 5


on 04-19-2023 08:41:52 GMT -05:00

https://www.coursehero.com/file/89946279/DS100-3-WS38pdf/
RIANO, Francis Anthony M APPLIED DATA SCIENCE

WORKSHEET 3.8: SUPERVISED LEARNING IN PYTHON

4 Date:
Use train_test_split from sklearn on your House votes data. Use 70% of the data for training and the rest for testing.
Add the following arguments to train_test_split: random_state = 21, stratify = y. Print out the predictions
for the test set and the model score.
Code

Output

This study source was downloaded by 100000857417487 from CourseHero.comPage 4 of 5


on 04-19-2023 08:41:52 GMT -05:00

https://www.coursehero.com/file/89946279/DS100-3-WS38pdf/
RIANO, Francis Anthony M APPLIED DATA SCIENCE

WORKSHEET 3.8: SUPERVISED LEARNING IN PYTHON

5 Date:
Import the gapminder file. Perform regression on the data (life expectancy as a function of fertility). Prepare a plot showing the
data points (in blue) and the linear model (in red). Print out the regression score.
Code

Output

This study source was downloaded by 100000857417487 from CourseHero.comPage 5 of 5


on 04-19-2023 08:41:52 GMT -05:00

https://www.coursehero.com/file/89946279/DS100-3-WS38pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like