0% found this document useful (0 votes)
6 views3 pages

Python

This document contains code to analyze and visualize two different datasets: the Iris dataset and the Auto MPG dataset. For the Iris dataset, the code downloads the data, parses it, and plots scatter plots to visualize the relationships between features for different iris classes. For the Auto MPG dataset, the code reads a local CSV file, cleans the data by handling missing values and converting datatypes, and generates descriptive statistics and visualizations like bar plots and scatter plots to analyze relationships between variables like MPG, weight, horsepower. Key libraries used include requests, NumPy, Pandas, and Matplotlib.

Uploaded by

Stefania Guzman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python

This document contains code to analyze and visualize two different datasets: the Iris dataset and the Auto MPG dataset. For the Iris dataset, the code downloads the data, parses it, and plots scatter plots to visualize the relationships between features for different iris classes. For the Auto MPG dataset, the code reads a local CSV file, cleans the data by handling missing values and converting datatypes, and generates descriptive statistics and visualizations like bar plots and scatter plots to analyze relationships between variables like MPG, weight, horsepower. Key libraries used include requests, NumPy, Pandas, and Matplotlib.

Uploaded by

Stefania Guzman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FLORES

import requests
import numpy
import matplotlib.pyplot as plt

r = requests.get('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')

renglones_iris = r.text.split('\n')
renglones_iris[:5]
renglones_iris[-4:]

[ renglon.split(',')[:-1] for renglon in renglones_iris[:-2]]


[list(map(float, renglon.split(',')[:-1]) ) for renglon in
renglones_iris[:-2]]

iris_data = [list(map(float, renglon.split(',')[:-1])) for renglon


in renglones_iris[:-2]]
iris = numpy.array(iris_data)
print(iris[:10])

x = iris[:50,0]
y = iris[:50,1]
plt.plot(x, y, 'r.')
plt.show()
plt.plot( iris[:50,0], iris[:50,1], 'r.') # Setosa
plt.plot( iris[51:100,0], iris[51:100,1], 'b.') # Virginica
plt.show()

plt.plot( iris[:50,0], iris[:50,1], 'r.') # Setosa


plt.plot( iris[51:100,0], iris[51:100,1], 'b.') # Virginica
plt.plot( iris[101:,0], iris[101:,1], 'g.')
plt.show()
PPT 3
CMD
python -m pip install matplotlib
python -m pip install pandas
python -m pip install numpy

CMD DE PYTHON
 https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/

import matplotlib.pyplot as plt


import pandas as pd
import numpy as np

df = pd.read_csv('C:/Users/laboratorio_bg/Downloads/datos-ejemplos/auto-mpg.data',
sep='\s+')
print(df)

df = pd.read_csv('C:/Users/laboratorio_bg/Downloads/datos-ejemplos/auto-mpg.data',
sep='\s+', header=None)

df2 = pd.read_csv('C:/Users/laboratorio_bg/Downloads/datos-ejemplo/auto-mpg.data',
sep='\s+', header=None,
names=['mpg','cylinders','displacement','horsepower','weight','acceleration',
'model_year','origin','car_name'])

df2

df2.dtypes

df2 = pd.read_csv('C:/Users/laboratorio_bg/Downloads/datos-ejemplo/auto-mpg.data',
sep='\s+', header=None,
names=['mpg','cylinders','displacement','horsepower','weight',
'acceleration','model_year','origin','car_name'], na_values='?')
df2 = pd.read_csv('C:/Users/laboratorio_bg/Downloads/datos-ejemplo/auto-mpg.data',
sep='\s+', header=None, na_values='?',
names=['mpg','cylinders','displacement','horsepower',
'weight','acceleration','model_year','origin','car_name'],
dtype={'mpg':'f4','cylinders':'i4','displacement':'f4',
'horsepower':'f4','weight':'f4','acceleration':'f4',
'model_year':'i4','origin':'category','car_name':'category'})
df2["origin"]= df2["origin"].cat.rename_categories({"1":"usa","2":"japan","3":"germary"})

df2["origin"]= df2["origin"].cat.rename_categories({"1":"usa","2":"japan","3":"germary"})
df2['origin']

(Se ejecutan al mismo tiempo)

df2.dtypes
df2.describe()

df2['origin'].value_counts().plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x10d1d1cd0>
plt.show()

df2.plot.scatter(x='weight', y='mpg',c='horsepower',cmap='viridis');
plt.show()

You might also like