Using the data in the attached table info.csv
Find the k-nearest neighbors for record #10 using k = 3
Write a Python 3 program that solves the above problem
Python program must read the info.csv file from within the program
The info.csv file contains the following data table
1, 22, Single, 46156.98, Bad loss
2, 33, Married, 24188.10, Bad loss
3, 28, Other, 28787.34, Bad loss
4, 51, Other, 23886.72, Bad loss
5, 25, Single, 47281.44, Bad loss
6, 39, Single, 33994.90, Good risk
7, 54, Single, 28716.50, Good risk
8, 55, Married, 49186.75, Good risk
9, 50, Married, 46726.50, Good risk
10, 66, Married, 36120.34, Good risk
Answer:
# importing the required libraries
import numpy as np
import pandas as pd
from sklearn.neighbors import NearestNeighbors
from sklearn import preprocessing
# Storing the data provided and converting it to dataframe
data= [[1, 22, "Single", 46156.98, "Bad loss"],[2, 33,
"Married", 24188.10, "Bad loss"],[3, 28, "Other", 28787.34, "Bad
loss"],
[4, 51, "Other", 23886.72, "Bad loss"],[5, 25, "Single", 47281.44,
"Bad loss"],[6, 39, "Single", 33994.90, "Good risk"],
[7, 54, "Single", 28716.50, "Good risk"],[8, 55, "Married",
49186.75, "Good risk"],[9, 50, "Married", 46726.50, "Good
risk"],
[10, 66, "Married", 36120.34, "Good risk"]]
df = pd.DataFrame(data, columns = ['rec','Age', 'Status', 'val', 'risk'])
# droping(deleting) the column representing the record number since it is managed by the df.
df.drop(columns=['rec'])
#converting string values to integer so that it can be operated by
the model
le = preprocessing.LabelEncoder()
le.fit(df.Status)
df.Status = le.transform(df.Status)
le.fit(df.risk)
df.risk = le.transform(df.risk)
df
# creating the model and fitting into the model
neigh = NearestNeighbors(n_neighbors=3)
neigh.fit(df)
# 1st array represents the distance and second shows the record
number (starting from 0) from which the distance is displayed
print(neigh.kneighbors(df.loc[[9]]))
Using the data in the attached table info.csv Find the k-nearest neighbors for record #10 using...
4.) Using k-Nearest Neighbors with k=3 and the following table, classify corn (sweetness = 6, crunchiness = 6) as either a fruit, protein, or vegetable. 3pts Crunchiness Ingredient apple bacon Sweetness 10 1 banana 10 Food type fruit protein fruit vegetable vegetable protein 1 10 10 carrot celery cheese 1
Classification in Python: Classification In this assignment, you will practice using the kNN (k-Nearest Neighbors) algorithm to solve a classification problem. The kNN is a simple and robust classifier, which is used in different applications. The goal is to train kNN algorithm to distinguish the species from one another. The dataset can be downloaded from UCI Machine Learning Repository: https://archive.ics.uci.edu/ml/machine-learning-databases/iris/ (Links to an external site.)Links to an external site.. Download `iris.data` file from the Data Folder. The Data Set description...
blockpy python review 16 processing json files second pic is the report.json file data BlockPy: Review 16) Process JSON The given file contains JSON data. Use the data associated with the "Employees" key (a list inside of a dictionary inside of a dictionary inside of a dictionary) to plot the distribution of employees. Note: You cannot embed the contents of the file directly in your program. Use the appropriate file handling style to access the data in the file. Note:...
Using the data in the file named “Dataset 1,” to determine is there was a change in the number of tons of paper used after the implementation of a recycling program in 25 different districts. a. Is this study using dependent or independent samples? b. What is your research hypothesis? c. Using Excel, calculate your test statistic and p-value. Paste the output here. d. What do you conclude? Below is the data set that is mentioned above Before Recycling 20...
The following data represents the number of consecutive minutes (to the nearest minute) 2. spent on mobile phones by students attending the University of A. 23 2 26 40 22 52 28 40 19 55 50 52 51 46 51 60 59 45 26 2 48 1 34 10 18 45 29 41 11 43 50 32 37 15 57 17 57 35 50 45 7 22 15 13 20 13 15 32 13 39 25 38 31 16 7...
Student Name Student Number 18. Describe the center and spread of the data using either the mean and standard deviation or the five-number summary. Justify your choice by constructing a box-and-whisker plot for the data. Be sure to include the scale. A. 47, 16, 70, 80, 28, 33, 91, 55, 60, 45, 86, 54, 30, 98, 34, 87, 44, 35,64,58, 27,67, 72,68, 31, 95, 37, 41, 97,56, 49, 71, 84, 66, 45, 93 B. 40, 39, 37, 26, 25, 40,...
Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...
Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a) In-Order Traversal b) Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...
We sometimes hear that getting married is good for your career. The table below presents data from one of the studies behind this generalization. To avoid gender effects, the investigators looked only at men. The data describe the marital status and the job level of all the male managers and professionals employed by a large manufacturing firm. The firm assigns each position a grade that reflects the value of that particular job to the company. The authors of the study...
Find the output voltage of this zener diode source. From the table in the data sheet attached to the end of this file, find the zener voltage specifications for the 1N5231B part. What is the current flowing through the zener diode? Using Figs. 8 and 10 of the data sheet, estimate the output resistance of the source. Calculate the drop in the output voltage if a 20 k Ohm resistor is placed across the output.