自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

我最近偶遇的六個(gè)很酷的Python庫

譯文
開發(fā) 后端
Python是機(jī)器學(xué)習(xí)不可或缺的一部分,庫讓我們的生活更簡單。最近,我在處理機(jī)器學(xué)習(xí)項(xiàng)目時(shí)遇到了6個(gè)很棒的庫。它們幫我節(jié)省了大量時(shí)間,本文將介紹它們。

[[422968]]

【51CTO.com快譯】Python是機(jī)器學(xué)習(xí)不可或缺的一部分,庫讓我們的生活更簡單。最近,我在處理機(jī)器學(xué)習(xí)項(xiàng)目時(shí)遇到了6個(gè)很棒的庫。它們幫我節(jié)省了大量時(shí)間,本文將介紹它們。

1. clean-text

clean-text是真正很出色的庫,如果您需要處理抓取內(nèi)容或社交媒體數(shù)據(jù),它應(yīng)該是您的首選。最棒的是它不需要任何冗長的花哨代碼或正則表達(dá)式來清理數(shù)據(jù)。不妨看幾個(gè)例子:

安裝

  1. !pip install cleantext 

例子

  1. #Importing the clean text library 
  2. from cleantext import clean# Sample texttext = """ Zürich, largest city of Switzerland and capital of the canton of 633Zürich. Located in an Al\u017eupine. (https://google.com). Currency is not ₹"""# Cleaning the "text" with clean textclean(text,  
  3.       fix_unicode=True,  
  4.       to_ascii=True,  
  5.       lower=True,  
  6.       no_urls=True,  
  7.       no_numbers=True,  
  8.       no_digits=True,  
  9.       no_currency_symbols=True,  
  10.       no_punct=True,  
  11.       replace_with_punct=" ",  
  12.       replace_with_url="",  
  13.       replace_with_number="",  
  14.       replace_with_digit=" ",  
  15.       replace_with_currency_symbol="Rupees"

輸出

我們從上面可以看到,它在Zurich一詞中含有Unicode(字母“u”已被編碼)、ASCII 字符(在Al\u017eupine 中)、盧比貨幣符號(hào)、HTML 鏈接和標(biāo)點(diǎn)符號(hào)。

您只需在clean函數(shù)中提及所需的ASCII、Unicode、URL、數(shù)字、貨幣和標(biāo)點(diǎn)符號(hào)?;蛘?,可以將它們換成上述函數(shù)中的替換參數(shù)。比如說,我將盧比符號(hào)換成了Rupees。

絕對(duì)不需要使用正則表達(dá)式或長代碼。非常方便的庫,如果您想清理來自抓取內(nèi)容或社交媒體數(shù)據(jù)的文本,尤為方便。您還可以根據(jù)要求單獨(dú)傳遞參數(shù),而不是將它們?nèi)拷M合在一起。

欲了解更多詳細(xì)信息,請查看該GitHub 存儲(chǔ)庫。

2. drawdata

drawdata是我發(fā)現(xiàn)的另一個(gè)很酷的Python庫。需要向團(tuán)隊(duì)解釋機(jī)器學(xué)習(xí)概念這種情形有多常見?肯定經(jīng)常發(fā)生,因?yàn)閿?shù)據(jù)科學(xué)注重團(tuán)隊(duì)合作。該庫可幫助您在Jupyter筆記本中繪制數(shù)據(jù)集。

我向團(tuán)隊(duì)解釋機(jī)器學(xué)習(xí)概念時(shí),確實(shí)很喜歡使用這個(gè)庫。感謝創(chuàng)建這個(gè)庫的開發(fā)人員!

Drawdata僅面向有四個(gè)類的分類問題。

安裝

  1. !pip install drawdata 

例子

  1. # Importing the drawdata  
  2. from drawdata import draw_scatterdraw_scatter() 

輸出

執(zhí)行draw_Scatter()后將打開上述繪圖窗口。很顯然,有四個(gè)類,即A、B、C和D??梢渣c(diǎn)擊任何類,并繪制所需的點(diǎn)。每個(gè)類代表圖形中的不同顏色。您還可以選擇將數(shù)據(jù)作為csv或json文件來下載。此外,可以將數(shù)據(jù)復(fù)制到剪貼板,并從下面的代碼中讀?。?/p>

  1. #Reading the clipboardimport pandas as pd  
  2. df = pd.read_clipboard(sep=","
  3. df 

這個(gè)庫的局限之一是它只提供有四個(gè)類的兩個(gè)數(shù)據(jù)點(diǎn)。但除此之外,它絕對(duì)有其價(jià)值。欲了解更多詳細(xì)信息,請查看該GitHub 鏈接。

3. Autoviz

我永遠(yuǎn)不會(huì)忘記花在使用matplotlib進(jìn)行探索性數(shù)據(jù)分析上的時(shí)間。有很多簡單的可視化庫。然而,我最近發(fā)現(xiàn)Autoviz僅用一行代碼即可自動(dòng)直觀顯示任何數(shù)據(jù)集。

安裝

  1. !pip install autoviz 

例子

我在這個(gè)例子中使用了IRIS數(shù)據(jù)集。

  1. # Importing Autoviz class from the autoviz library 
  2. from autoviz.AutoViz_Class import AutoViz_Class#Initialize the Autoviz class in a object called df 
  3. df = AutoViz_Class()# Using Iris Dataset and passing to the default parametersfilename = "Iris.csv" 
  4. sep = ","graph = df.AutoViz( 
  5.     filename, 
  6.     sep=","
  7.     depVar=""
  8.     dfte=None, 
  9.     header=0, 
  10.     verbose=0, 
  11.     lowess=False
  12.     chart_format="svg"
  13.     max_rows_analyzed=150000, 
  14.     max_cols_analyzed=30, 

上述參數(shù)是默認(rèn)值。欲了解更多信息,請點(diǎn)擊此處。

輸出

我們可以看到所有的視覺元素,僅用一行代碼完成我們的EDA。有很多自動(dòng)可視化庫,但我特別喜歡這個(gè)庫。

4. Mito

每個(gè)人都喜歡Excel,是不是?它是初次探索數(shù)據(jù)集的最簡單方法之一。幾個(gè)月前我遇到了Mito,但最近才試了試,我絕對(duì)愛不釋手!

它是一個(gè)帶GUI支持的Jupyter-lab擴(kuò)展Python庫,添加了電子表格功能。您可以加載 csv數(shù)據(jù),將數(shù)據(jù)集作為電子表格來編輯,它可自動(dòng)生成Pandas代碼。很酷。

Mito值得寫一篇完整的博文來介紹,但是今天不作詳細(xì)介紹。這是為您提供的簡單的任務(wù)演示。欲知更多詳情,請查看此處。

安裝

  1. #First install mitoinstaller in the command prompt 
  2. pip install mitoinstaller# Then, run the installer in the command prompt 
  3. python -m mitoinstaller install# Then, launch Jupyter lab or jupyter notebook from the command prompt 
  4. python -m jupyter lab 

想了解安裝方面的更多信息,請查看此處。

  1. # Importing mitosheet and ruuning this in Jupyter labimport mitosheet 
  2. mitosheet.sheet() 

執(zhí)行上述代碼后,mitosheet將在jupyter實(shí)驗(yàn)室中打開。我使用IRIS數(shù)據(jù)集。首先,我創(chuàng)建了兩個(gè)新列。一個(gè)是Sepal平均長度,另一個(gè)是Sepal總寬度。其次,我更改了Sepal平均長度的列名。最后,我為Sepal平均長度列創(chuàng)建了一個(gè)直方圖。

執(zhí)行上述步驟后,代碼會(huì)自動(dòng)生成。

輸出

為上述步驟生成以下代碼:

  1. from mitosheet import * # Import necessary functions from Mito 
  2. register_analysis('UUID-119387c0-fc9b-4b04-9053-802c0d428285') # Let Mito know which analysis is being run# Imported C:\Users\Dhilip\Downloads\archive (29)\Iris.csv 
  3. import pandas as pd 
  4. Iris_csv = pd.read_csv('C:\Users\Dhilip\Downloads\archive (29)\Iris.csv')# Added column G to Iris_csv 
  5. Iris_csv.insert(6, 'G', 0)# Set G in Iris_csv to =AVG(SepalLengthCm) 
  6. Iris_csv['G'] = AVG(Iris_csv['SepalLengthCm'])# Renamed G to Avg_Sepal in Iris_csv 
  7. Iris_csv.rename(columns={"G""Avg_Sepal"}, inplace=True

5. Gramformer

另一個(gè)出色的庫Gramformer基于生成模型,可幫助我們糾正句子中的語法。這個(gè)庫有三個(gè)模型,有檢測器、熒光筆和校正器。檢測器識(shí)別文本是否有錯(cuò)誤的語法。熒光筆標(biāo)記錯(cuò)誤的部分,校正器修復(fù)錯(cuò)誤。Gramformer是完全開源的軟件,目前處于早期階段。但它不適合長段落,因?yàn)樗鼉H適用于句子,已針對(duì)64個(gè)字符長度的句子進(jìn)行了訓(xùn)練。

目前,校正器和熒光筆模型切實(shí)有用。不妨看幾個(gè)例子。

安裝

  1. !pip3 install -U git+https://github.com/PrithivirajDamodaran/Gramformer.git 

為Gramformer創(chuàng)建實(shí)例

  1. gf = Gramformer(models = 1, use_gpu = False) # 1=corrector, 2=detector (presently model 1 is working, 2 has not implemented) 

例子

  1. #Giving sample text for correction under gf.correctgf.correct(""" New Zealand is island countrys in southwestern Paciific Ocaen. Country population was 5 million """

輸出

我們從上面的輸出中可以看到它糾正了語法,甚至糾正了拼寫錯(cuò)誤。一個(gè)非常棒的庫,功能也很棒。我還沒有在這里試過熒光筆,您可以試試,查看該GitHub文檔,以獲取更多詳細(xì)信息

6. Styleformer

在使用Gramformer方面的良好體驗(yàn)鼓勵(lì)我尋找更多獨(dú)特的庫。我因此發(fā)現(xiàn)了Styleformer,這是另一個(gè)極具出色的Python庫。Gramformer和Styleformer都是由Prithiviraj Damodaran創(chuàng)建的,兩者都基于生成模型。感謝創(chuàng)建者開源。

Styleformer幫助將隨意句轉(zhuǎn)換成正式句、將正式句轉(zhuǎn)換成隨意句、將主動(dòng)句轉(zhuǎn)換成被動(dòng)句以及將被動(dòng)句轉(zhuǎn)換成主動(dòng)句。

不妨看幾個(gè)例子:

安裝

  1. !pip install git+https://github.com/PrithivirajDamodaran/Styleformer.git 

為Styleformer創(chuàng)建實(shí)例

  1. sf = Styleformer(style = 0)# style = [0=Casual to Formal, 1=Formal to Casual, 2=Active to Passive, 3=Passive to Active etc..] 

例子

  1. # Converting casual to formal sf.transfer("I gotta go"

  1. # Formal to casual  
  2. sf = Styleformer(style = 1)     # 1 -> Formal to casual# Converting formal to casual 
  3. sf.transfer("Please leave this place"

  1. # Active to Passive  
  2. sf = Styleformer(style = 2)     # 2-> Active to Passive# Converting active to passive 
  3. sf.transfer("We are going to watch a movie tonight."

  1. # passive to active 
  2. sf = Styleformer(style = 2)     # 2-> Active to Passive# Converting passive to active 
  3. sf.transfer("Tenants are protected by leases"

看到上面的輸出,轉(zhuǎn)換準(zhǔn)確。我使用這個(gè)庫將隨意句轉(zhuǎn)換成正式句,尤其是在我有一次分析時(shí)用于社交媒體帖子。欲了解更多詳細(xì)信息,請查看GitHub。

您可能熟悉了前面提到的一些庫,但像Gramformer和Styleformer這樣的庫是最近出現(xiàn)的庫。它們被嚴(yán)重低估了,當(dāng)然值得廣為人知,因?yàn)樗鼈優(yōu)槲夜?jié)省了大量時(shí)間,我在NLP項(xiàng)目中大量使用它們。

原文標(biāo)題:6 Cool Python Libraries That I Came Across Recently,作者:Dhilip Subramanian

【51CTO譯稿,合作站點(diǎn)轉(zhuǎn)載請注明原文譯者和出處為51CTO.com】

責(zé)任編輯:華軒 來源: 51CTO
相關(guān)推薦

2022-06-01 09:06:58

ES6數(shù)組函數(shù)

2024-02-17 22:05:58

Python開發(fā)

2024-01-08 16:27:59

ES6函數(shù)

2024-10-11 10:00:00

Python編程

2017-05-03 10:45:47

Python運(yùn)行效率竅門

2021-10-27 10:15:25

Python新特性編程語言

2022-03-26 09:32:54

Python編程映射

2022-11-15 16:54:54

2022-04-18 07:51:31

Web框架模板

2022-06-28 10:17:23

安全職位首席信息安全官

2022-05-13 09:55:19

Python內(nèi)置函數(shù)

2023-04-26 00:46:03

Python自然語言處理庫

2024-03-06 10:50:30

云計(jì)算云實(shí)例云提供商

2021-07-16 10:27:07

ITIT領(lǐng)導(dǎo)IT管理

2022-04-07 12:03:28

云安全CSPM云計(jì)算

2012-09-19 16:09:43

2016-07-25 18:10:55

2016-12-15 09:53:07

自學(xué)編程技巧

2023-09-28 13:27:40

Tailwind瀏覽器CSS

2024-03-11 14:34:04

JavaScript開發(fā)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)