<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          dython是什么?真有這個庫,厲害了

          共 5870字,需瀏覽 12分鐘

           ·

          2021-08-27 14:04

          ↑↑↑關(guān)注后"星標"簡說Python

          人人都可以簡單入門Python、爬蟲、數(shù)據(jù)分析
           簡說Python推薦 

          來源:Python大數(shù)據(jù)分析

          作者:費弗里

          盡管已經(jīng)有了scikit-learnstatsmodels、seaborn等非常優(yōu)秀的數(shù)據(jù)建模庫,但實際數(shù)據(jù)分析過程中常用到的一些功能場景仍然需要編寫數(shù)十行以上的代碼才能實現(xiàn)。

          而今天要給大家推薦的dython就是一款集成了諸多實用功能的數(shù)據(jù)建模工具庫,幫助我們更加高效地完成數(shù)據(jù)分析過程中的諸多任務(wù):

          通過下面兩種方式均可完成對dython的安裝:

          pip install dython

          或:

          conda install -c conda-forge dython

          dython中目前根據(jù)功能分類劃分為以下幾個子模塊:

          • 「data_utils」

          data_utils子模塊集成了一些基礎(chǔ)性的數(shù)據(jù)探索性分析相關(guān)的API,如identify_columns_with_na()可用于快速檢查數(shù)據(jù)集中的缺失值情況:

          >> df = pd.DataFrame({'col1': ['a', np.nan, 'a''a'], 'col2': [3, np.nan, 2, np.nan], 'col3': [1.2.3.4.]})
          >> identify_columns_with_na(df)
            column  na_count
          1   col2         2
          0   col1         1

          identify_columns_by_type()可快速選擇數(shù)據(jù)集中具有指定數(shù)據(jù)類型的字段:

          >> df = pd.DataFrame({'col1': ['a''b''c''a'], 'col2': [3421], 'col3': [1.2.3.4.]})
          >> identify_columns_by_type(df, include=['int64''float64'])
          ['col2''col3']

          one_hot_encode()可快速對數(shù)組進行「獨熱編碼」

          >> one_hot_encode([1,0,5])
          [[0. 1. 0. 0. 0. 0.]
           [1. 0. 0. 0. 0. 0.]
           [0. 0. 0. 0. 0. 1.]]

          split_hist()則可以快速繪制分組直方圖,幫助用戶快速探索數(shù)據(jù)集特征分布:

          import pandas as pd
          from sklearn import datasets
          from dython.data_utils import split_hist

          # Load data and convert to DataFrame
          data = datasets.load_breast_cancer()
          df = pd.DataFrame(data=data.data, columns=data.feature_names)
          df['malignant'] = [not bool(x) for x in data.target]

          # Plot histogram
          split_hist(df, 'mean radius', split_by='malignant', bins=20, figsize=(15,7))
          • 「nominal」

          nominal子模塊包含了一些進階的特征相關(guān)性度量功能,例如其中的associations()可以自適應(yīng)由連續(xù)型和類別型特征混合的數(shù)據(jù)集,并自動計算出相應(yīng)的PearsonCramer's V、Theil's U、條件熵等多樣化的系數(shù);cluster_correlations()可以繪制出基于層次聚類的相關(guān)系數(shù)矩陣圖等實用功能:

          • 「model_utils」

          model_utils子模塊包含了諸多對機器學習模型進行性能評估的工具,如ks_abc()

          from sklearn import datasets
          from sklearn.model_selection import train_test_split
          from sklearn.linear_model import LogisticRegression
          from dython.model_utils import ks_abc

          # Load and split data
          data = datasets.load_breast_cancer()
          X_train, X_test, y_train, y_test = train_test_split(data.data, data.target, test_size=.5, random_state=0)

          # Train model and predict
          model = LogisticRegression(solver='liblinear')
          model.fit(X_train, y_train)
          y_pred = model.predict_proba(X_test)

          # Perform KS test and compute area between curves
          ks_abc(y_test, y_pred[:,1])

          metric_graph()

          import numpy as np
          from sklearn import svm, datasets
          from sklearn.model_selection import train_test_split
          from sklearn.preprocessing import label_binarize
          from sklearn.multiclass import OneVsRestClassifier
          from dython.model_utils import metric_graph

          # Load data
          iris = datasets.load_iris()
          X = iris.data
          y = label_binarize(iris.target, classes=[012])

          # Add noisy features
          random_state = np.random.RandomState(4)
          n_samples, n_features = X.shape
          X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]

          # Train a model
          X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=0)
          classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True, random_state=0))

          # Predict
          y_score = classifier.fit(X_train, y_train).predict_proba(X_test)

          # Plot ROC graphs
          metric_graph(y_test, y_score, 'pr', class_names=iris.target_names)
          import numpy as np
          from sklearn import svm, datasets
          from sklearn.model_selection import train_test_split
          from sklearn.preprocessing import label_binarize
          from sklearn.multiclass import OneVsRestClassifier
          from dython.model_utils import metric_graph

          # Load data
          iris = datasets.load_iris()
          X = iris.data
          y = label_binarize(iris.target, classes=[012])

          # Add noisy features
          random_state = np.random.RandomState(4)
          n_samples, n_features = X.shape
          X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]

          # Train a model
          X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5, random_state=0)
          classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True, random_state=0))

          # Predict
          y_score = classifier.fit(X_train, y_train).predict_proba(X_test)

          # Plot ROC graphs
          metric_graph(y_test, y_score, 'roc', class_names=iris.target_names)
          • 「sampling」

          sampling子模塊則包含了boltzmann_sampling()weighted_sampling()兩種數(shù)據(jù)采樣方法,簡化數(shù)據(jù)建模流程。

          dython作為一個處于快速開發(fā)迭代過程的Python庫,陸續(xù)會有更多的實用功能引入,感興趣的朋友們可以前往https://github.com/shakedzy/dython查看更多內(nèi)容或?qū)Υ隧椖勘3株P(guān)注。


          以上就是本文的全部內(nèi)容,歡迎在評論區(qū)與我進行討論~

          --END--


          掃碼即可加我微信

          觀看朋友圈,獲取最新學習資源


          學習更多:
          整理了我開始分享學習筆記到現(xiàn)在超過250篇優(yōu)質(zhì)文章,涵蓋數(shù)據(jù)分析、爬蟲、機器學習等方面,別再說不知道該從哪開始,實戰(zhàn)哪里找了
          點贊、留言”就是對我最大的支持!
          瀏覽 80
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  大香蕉伊人免费看 | 国产黄色中文字幕 | 曰本色黄a大片免费 | 成人做爰黄 片视频真人 | 韩日精品在线 |