Python data science
With Python as the core language, it specializes in the field of "data science". The articles cover data analysis, data mining, machine learning and other dry goods, share a large number of data mining practical project analysis and explanation, and massive learning resources.
In order for everyone to have a preliminary understanding of the Python libraries commonly used in artificial intelligence, so as to choose a library that can meet their needs for learning, a brief and comprehensive introduction to the more common artificial intelligence libraries is given.
1、Numpy
NumPy(Numerical Python)
It is Python
an extended program library that supports a large number of dimensional arrays and matrix operations. In addition, it also provides a large number of mathematical function libraries for array operations. The Numpy
underlying use is C语言
written. Objects are directly stored in the array instead of object pointers, so its operation efficiency is much higher. Yu 纯Python代
code. 纯Python
We can compare the speed with the calculation of the sin value of the list in the example Numpy库
:
import numpy as np
import math
import random
import time
start = time.time()
for i in range(10):
list_1 = list(range(1,10000))
for j in range(len(list_1)):
list_1[j] = math.sin(list_1[j])
print("使用纯Python用时{}s".format(time.time()-start))
start = time.time()
for i in range(10):
list_1 = np.array(np.arange(1,10000))
list_1 = np.sin(list_1)
print("使用Numpy用时{}s".format(time.time()-start))
From the following running results, you can see that using Numpy
the library is faster than code written in pure Python:
0.017444372177124023s using pure Python and 0.001619577407836914s using Numpy
2.
item_get-Get Taobao product details
taobao.item_get
public parameter
Request address: apply for calling KEY
name | type | must | describe |
---|---|---|---|
key | String | yes | Call key (must be spliced in the URL in GET mode) |
secret | String | yes | call key |
api_name | String | yes | API interface name (included in the request address) [item_search, item_get, item_search_shop, etc.] |
cache | String | no | [yes, no] The default is yes, the cached data will be called, and the speed is relatively fast |
result_type | String | no | [json,jsonu,xml,serialize,var_export] returns the data format, the default is json, and the content output by jsonu can be read directly in Chinese |
lang | String | no | [cn,en,ru] translation language, default cn Simplified Chinese |
version | String | no | API version |
request code
<?php
// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/taobao/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=652874751412&is_promotion=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
3、OpenCV
OpenCV
is a cross-platform computer vision library that can run on Linux, Windows and Mac OS operating systems. It's lightweight and efficient—consisting of a series of C functions and a handful of C++ classes, it also provides Python
interfaces that implement many common algorithms in image processing and computer vision. The following code tries to use some simple filters, including image smoothing, Gaussian blur, etc.:
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('h89817032p0.png')
kernel = np.ones((5,5),np.float32)/25
dst = cv.filter2D(img,-1,kernel)
blur_1 = cv.GaussianBlur(img,(5,5),0)
blur_2 = cv.bilateralFilter(img,9,75,75)
plt.figure(figsize=(10,10))
plt.subplot(221),plt.imshow(img[:,:,::-1]),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(222),plt.imshow(dst[:,:,::-1]),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.subplot(223),plt.imshow(blur_1[:,:,::-1]),plt.title('Gaussian')
plt.xticks([]), plt.yticks([])
plt.subplot(224),plt.imshow(blur_1[:,:,::-1]),plt.title('Bilateral')
plt.xticks([]), plt.yticks([])
plt.show()
4. Open AI interface data
Parameter description: Text mode parameter: &_o_args={"prompt": "When will the Chinese team enter the World Cup","max_tokens":200} Prompt text, max_token vocabulary maximum image mode parameter: &_o_args={"prompt":"Earth
" ,"n":10 } prompt picture description text, n Returns
the number of pictures
request example
<?php
// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/openai/custom/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&method=";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
5.
item_search - search for items by keyword
1688.item_search
request parameters
Pricing:q=start_price=0&end_price=0&page=1&cat=0&discount_only=&sort=&page_size=40&seller_info=no&nick=&seller_info=&nick=&ppath=&imgid=&filter=
Parameter description: q: search keyword
cat: category ID
start_price: start price
end_price: end price
sort: sort [bid,_bid,_sale,_credit]
(bid: total price, sale: sales volume, credit credit, add _ prefix as from Sort from big to small)
page: number of pages page_size: number of treasures per page, default 40
filter: additional filter parameters, such as: filter=filtId:1,2,3,4;activityType:1,2,3,4;city :Tianjin;quantityBegin:1000
filtId Filter: Delivery within 48 hours, replacement within 7+ days, free shipping insurance, free credit;
activityType Promotion type: free shipping, source of goods, partnership, mobile phone exclusive price
city Region: region name
quantityBegin MOQ: number
request code
<?php
// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/1688/item_search/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&q=女装&start_price=0&end_price=0&page=1&cat=0&discount_only=&sort=&page_size=40&seller_info=no&nick=&seller_info=&nick=&ppath=&imgid=&filter=";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
6.
item_search_img-Search 1688 products by image (Pailitao)
1688.item_search_img
public parameter
Request Address: Apply for registration address
name | type | must | describe |
---|---|---|---|
key | String | yes | Call key (must be spliced in the URL in GET mode) |
secret | String | yes | call key |
api_name | String | yes | API interface name (included in the request address) [item_search, item_get, item_search_shop, etc.] |
cache | String | no | [yes, no] The default is yes, the cached data will be called, and the speed is relatively fast |
result_type | String | no | [json,jsonu,xml,serialize,var_export] returns the data format, the default is json, and the content output by jsonu can be read directly in Chinese |
lang | String | no | [cn,en,ru] translation language, default cn Simplified Chinese |
version | String | no | API version |
<?php
// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/1688/item_search_img/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&imgid=http://g-search3.alicdn.com/img/bao/uploaded/i4/O1CN01IDpcD81zHbpHs1YgT_!!2200811456689.jpg";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
7.
item_get_app-Get the original data of Taobao app product details
taobao.item_get_app The product details interface with the most complete data can get coupon data and special parameters
<?php
// 请求示例 url 默认请求参数已经URL编码处理
// 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.…….cn/help/demo/sdk/demo-sign.php
$method = "GET";
$url = "https://api-gw.…….cn/taobao/item_get_app/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=520813250866";
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
var_dump(curl_exec($curl));
?>
8.
Pinduoduo API return value description for fetching product details by ID
item_get-Get product details according to ID
pinduoduo. item_get
public parameter
Request address: apply to call the KEY address
name | type | must | describe |
---|---|---|---|
key | String | yes | Call key (must be spliced in the URL in GET mode) |
secret | String | yes | call key |
api_name | String | yes | API interface name (included in the request address) [item_search, item_get, item_search_shop, etc.] |
cache | String | no | [yes, no] The default is yes, the cached data will be called, and the speed is relatively fast |
result_type | String | no | [json,jsonu,xml,serialize,var_export] returns the data format, the default is json, and the content output by jsonu can be read directly in Chinese |
lang | String | no | [cn,en,ru] translation language, default cn Simplified Chinese |
version | String | no | API version |
request parameters
Request parameter: num_iid=1620002566
Parameter description: num_iid: product ID;
response parameters
Version: Date:
name | type | must | example value | describe |
---|---|---|---|---|
num_id |
String | 0 | 1999629976 | Product ID |
title |
String | 0 | 2019 new women's short-sleeved t-shirt women's summer loose Korean casual tops all-match bat shirt five-point sleeve T-shirt | product title |
price |
Float | 0 | 8.8 | price |
minGroupPrice |
String | 0 | ||
maxGroupPrice |
String | 0 | ||
total_price |
Float | 0 | ||
orginal_price |
Float | 0 | original price | |
nick |
String | 0 | Yayi Clothing 1688 | seller nickname |
num |
Int | 0 | 233 | in stock |
sales |
Int | 0 | 76 | Sales |
detail_url |
String | 0 | http://yangkeduo.com/goods.html?goods_id=1999629976 | baby link |
desc |
String | 0 | Our store defaults to STO Express [there is also Best Huitong Zhongtong Express Zhongtong Yunda Post]. The merchant suggested size is for reference only. If you have any other questions, please contact customer service in time! If you like it, buy it quickly, quality assurance, rest assured to buy, and happy to wear! | Commodity Remarks |
item_imgs |
Mix | 0 | [{"url": "//t00img.yangkeduo.com/t05img/images/2018-06-28/24bcb29df1195edaea840afd3e1bdaf9.jpeg?imageMogr2/strip%7CimageView2/2/w/1300/q/80"}] | 宝贝图片列表 |
pic_url |
String | 0 | //t00img.yangkeduo.com/t05img/images/2018-06-28/24bcb29df1195edaea840afd3e1bdaf9.jpeg?imageMogr2/thumbnail/150x/quality/50 | 宝贝图片 |
props_name |
String | 0 | 商品属性名 | |
prop_imgs |
Mix | 0 | {"prop_img": [ {"properties": "0:0;1:1", "url": "//t00img.yangkeduo.com/t10img/images/2018-06-28/5c8f783ab2c4fea0ffea8fac73d8b2c2.jpeg"}]} | 商品属性图片列表 |
props |
Mix | 0 | 商品详情 | |
skus |
Mix | 0 | {"sku": [{"price": "16.56", "total_price": null, "orginal_price": "20.9", "properties": "0:0;1:1", "properties_name": "0:0:颜色:黑色;1:1:尺码:M【75-100斤】", "quantity": 221, "sku_id": 36410965966}] | 商品规格信息 |
props_list |
Mix | 0 | { "0:0": "Color: Black","1:1": "Size: M【75-100kg】"} | Commodity attributes |
props_img |
Mix | 0 | {"0:0;1:1": "//t00img.yangkeduo.com/t10img/images/2018-06-28/5c8f783ab2c4fea0ffea8fac73d8b2c2.jpeg"} | property picture |
property_alias |
String | 0 | Product attribute alias | |
seller_info |
Mix | 0 | {"nick": "雅怡服饰1688", "city": "", "level": null, "rate": null, "score": 4.27, "delivery_score": 4.37, "item_score": 4.38, "shop_type": "", "user_num_id": "", "sid": 99033, "shop_name": "雅怡服饰1688", "zhuy": "", "menu": [] } | seller info |
shop_item |
Mix | 0 | [] | |
relate_items |
Mix | 0 | [] |