Question

In: Computer Science

This is A PYTHON Question. Developing a machine learning system for a given dataset. Dataset Diabetes...

This is A PYTHON Question.

Developing a machine learning system for a given dataset.

Dataset

Diabetes dataset - https://www.kaggle.com/uciml/pima-indians-diabetes-database

Algorithms

Either one of the following:

1. K-Nearest Neighbors

2. Support Vector Machines

3. Neural Networks

Notes:

Explain your choice of algorithms and analyze the models developed.

Show what patterns/insights can be extracted from your chosen dataset and the selected algorithms.

Solutions

Expert Solution

Sorry that link is not working

I'm chosing support vector machine, because svm is very good at labeled data, so i choosed svm

if you have any problem in code, please let me know, you if you get desired output please upvote, any problem please mention in comment section

import pandas as pd
import requests
import csv
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn import svm
import numpy as np

payload = {
    '__RequestVerificationToken': '',
    'username': '',
    'password': '',
    'rememberme': 'false'
}

loginURL = 'https://www.kaggle.com/account/login'
dataURL = "https://www.kaggle.com/uciml/pima-indians-diabetes-database/downloads/diabetes.csv"

with requests.Session() as c:
    response = c.get(loginURL).text
    AFToken = response[response.index('antiForgeryToken')+19:response.index('isAnonymous: ')-12]
    #print("AntiForgeryToken={}".format(AFToken))
    payload['__RequestVerificationToken']=AFToken
    c.post(loginURL + "?isModal=true&returnUrl=/", data=payload)
    download = c.get(dataURL)
    decoded_content = download.content.decode('utf-8')
    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    my_list = list(cr)
    #for row in my_list:
    #    print(row)


df = pd.DataFrame(my_list)
def plot_decision_regions(X, y, classifier,test_idx=None, resolution=0.02):
    # setup marker generator and color map
    markers = ('s', 'x', 'v', '^', 'o')
    colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
    cmap = ListedColormap(colors[:len(np.unique(y))])
    # plot the decision surface
    x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution),
                           np.arange(x2_min, x2_max, resolution))
    Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)
    Z = Z.reshape(xx1.shape)
    plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)
    plt.xlim(xx1.min(), xx1.max())
    plt.ylim(xx2.min(), xx2.max())
    # plot all samples
    X_test, y_test = X[test_idx, :], y[test_idx]
    for idx, cl in enumerate(np.unique(y)):
        plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1],
                    alpha=0.8, c=cmap(idx),
                    marker=markers[idx], label=cl)
    # highlight test samples
    if test_idx:
        X_test, y_test = X[test_idx, :], y[test_idx]
        plt.scatter(X_test[:, 0], X_test[:, 1], c='',
                    alpha=1.0, linewidth=1, marker='v',
                    s=55, label='test set')

X = df[['Glucose','BMI']]
y = df['Outcome']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
X_train = np.array(X_train)
y_train = np.array(y_train)
X_test = np.array(X_test)
y_test = np.array(y_test)
machine1 = svm.SVC(kernel = 'linear')
machine1.fit(X_train,y_train)
y_pred = machine1.predict(X_test)
plot_decision_regions(X_train, y_train, machine1)
plt.show



Related Solutions

Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn...
Machine Learning do using python on jupyter notebook 1. Linear Regression Dataset used: Diabetes from sklearn You are asked to solve a regression problem in the Diabetes dataset. Please review the Diabetes dataset used before creating a program to decide which attributes will be used in the regression process. please use the cross-validation step to produce the best evaluation of the model. All you have to do is • Perform linear regression using the OLS (Ordinary Least Square) method (sklearn.linear_model.LinearRegression)...
This is a machine learning question. Please use python and google colab format. PLEASE USE BASIC...
This is a machine learning question. Please use python and google colab format. PLEASE USE BASIC MACHINE LEARNING CODES. Using the Kaggle diamonds dataset, construct a KNN estimator to predict diamond prices. Choose an appropriate K value and predict the price of a diamond with the following parameters: "carat' : 0.32, 'cut' : Ideal, 'color' : E, 'clarity' : IF, 'depth' : 60.7, 'table' : 58.0, 'x' : 4.46, 'y' : 4.48,  'z': 2.71". Please change the cut, color and clarity...
Question: Suppose you are designing a machine learning system to determine if transfer course credit should...
Question: Suppose you are designing a machine learning system to determine if transfer course credit should be awarded to incoming transfer students and for what class. Describe the type of data you believe you will need to collect to design and train this system. What evaluation metrics will you use? What experimental design or special considerations need to be considered when designing this system?
Given a dataset of random numbers, use Python to calculate: (a) Estimates for the sample mean...
Given a dataset of random numbers, use Python to calculate: (a) Estimates for the sample mean and sample variance without using inbuilt functions. (b) Suppose now that the standard deviation is known to be 0.25. Compute a 90% confidence interval for the population mean. (python libraries can be used to calculate the confidence interval) Data: 8.91E+00 1.53E+01 5.98E+00 6.39E+00 1.54E+00 1.05E+01 1.87E+00 2.14E+00 6.50E+00 3.20E+00 3.10E+00 5.16E+00 6.04E-01 1.75E+00 1.27E+00 3.15E+00 5.09E+00 5.19E-01 5.23E+00 4.17E+00 2.34E+01 4.94E+00 8.85E+00 1.66E-01 6.38E+00...
I need this code to be written in Python: Given a dataset, D, which consists of...
I need this code to be written in Python: Given a dataset, D, which consists of (x,y) pairs, and a list of cluster assignments, C, write a function centroids(D, C) that computes the new (x,y) centroid for each cluster. Your function should return a list of the new cluster centroids, with each centroid represented as a list of x, y: def centroid(D, C):
This is a maching learning question. Using the Kaggle diamonds dataset, build a KNN based estimator...
This is a maching learning question. Using the Kaggle diamonds dataset, build a KNN based estimator for estimating the price of a diamond and propose an appropriate K value. Please use python and google colab format. Thank you!
Will the 5 components of an information system still be applicable when machine learning and robotic...
Will the 5 components of an information system still be applicable when machine learning and robotic technology becomes omnipresent (i.e. universal)? Why or why not?
Question: What are the impact of Virtual and augmented reality and Machine learning and artificial intelligence...
Question: What are the impact of Virtual and augmented reality and Machine learning and artificial intelligence on the following questions relating to the healthcare industry? ?? Can it lower the cost of maintaining your legacy systems? Will it enable your organization to improve business processes? Will it improve interoperability of systems? Will it simplify or standardize IT interfaces? Does it define new computing or communication standards? Can this technology be used to re-engineer a mission-critical business process? Will employees see...
1. Define the concept of “Machine Learning”. 2. Summarise two applications of machine learning and the...
1. Define the concept of “Machine Learning”. 2. Summarise two applications of machine learning and the value it create.
explain the pathogenesis of developing acidosis from pnemonia explain the pathogenesis of developing acidosis from diabetes
explain the pathogenesis of developing acidosis from pnemonia explain the pathogenesis of developing acidosis from diabetes
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT