1. 程式人生 > 其它 >幾個有趣的函式實踐

幾個有趣的函式實踐

技術標籤:python機器學習

import os
import pandas as pd
import requests

PATH = r'/Users/DELL/Desktop/'
r=requests.get('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data')
with open(PATH + 'iris.data', 'w') as f:
    f.write(r.text)
os.chdir(PATH)
df = pd.read_csv(PATH + 'iris.data', names=['sepal length'
, 'sepal width', 'petal length', 'petal width', 'class']) df.head() df["class"].unique() df.describe() df.corr() df['class'] = df['class'].map({'Iris-setosa': 'SET', 'Iris-virginica': 'VIR', 'Iris-versicolor': 'VER'}) df df['wide petal'] = df['petal width'].apply(lambda v: 1 if v >=
1.3 else 0) df['petal area'] = df.apply(lambda r: r['petal length'] * r['petal width'],axis=1) df import numpy as np df.applymap(lambda v: np.log(v) if isinstance(v, float) else v)