最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用Python實(shí)現(xiàn)隨機(jī)森林算法的示例

 更新時(shí)間:2017年08月24日 10:50:44   作者:流風(fēng),飄然的風(fēng)  
這篇文章主要介紹了用Python實(shí)現(xiàn)隨機(jī)森林算法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

擁有高方差使得決策樹(secision tress)在處理特定訓(xùn)練數(shù)據(jù)集時(shí)其結(jié)果顯得相對(duì)脆弱。bagging(bootstrap aggregating 的縮寫)算法從訓(xùn)練數(shù)據(jù)的樣本中建立復(fù)合模型,可以有效降低決策樹的方差,但樹與樹之間有高度關(guān)聯(lián)(并不是理想的樹的狀態(tài))。

隨機(jī)森林算法(Random forest algorithm)是對(duì) bagging 算法的擴(kuò)展。除了仍然根據(jù)從訓(xùn)練數(shù)據(jù)樣本建立復(fù)合模型之外,隨機(jī)森林對(duì)用做構(gòu)建樹(tree)的數(shù)據(jù)特征做了一定限制,使得生成的決策樹之間沒有關(guān)聯(lián),從而提升算法效果。

本教程將實(shí)現(xiàn)如何用 Python 實(shí)現(xiàn)隨機(jī)森林算法。

  • bagged decision trees 與隨機(jī)森林算法的差異;
  • 如何構(gòu)建含更多方差的裝袋決策樹;
  • 如何將隨機(jī)森林算法運(yùn)用于預(yù)測(cè)模型相關(guān)的問題。

算法描述

這個(gè)章節(jié)將對(duì)隨機(jī)森林算法本身以及本教程的算法試驗(yàn)所用的聲納數(shù)據(jù)集(Sonar dataset)做一個(gè)簡(jiǎn)要介紹。

隨機(jī)森林算法

決策樹運(yùn)行的每一步都涉及到對(duì)數(shù)據(jù)集中的最優(yōu)分裂點(diǎn)(best split point)進(jìn)行貪婪選擇(greedy selection)。

這個(gè)機(jī)制使得決策樹在沒有被剪枝的情況下易產(chǎn)生較高的方差。整合通過提取訓(xùn)練數(shù)據(jù)庫(kù)中不同樣本(某一問題的不同表現(xiàn)形式)構(gòu)建的復(fù)合樹及其生成的預(yù)測(cè)值能夠穩(wěn)定并降低這樣的高方差。這種方法被稱作引導(dǎo)聚集算法(bootstrap aggregating),其簡(jiǎn)稱 bagging 正好是裝進(jìn)口袋,袋子的意思,所以被稱為「裝袋算法」。該算法的局限在于,由于生成每一棵樹的貪婪算法是相同的,那么有可能造成每棵樹選取的分裂點(diǎn)(split point)相同或者極其相似,最終導(dǎo)致不同樹之間的趨同(樹與樹相關(guān)聯(lián))。相應(yīng)地,反過來說,這也使得其會(huì)產(chǎn)生相似的預(yù)測(cè)值,降低原本要求的方差。

我們可以采用限制特征的方法來創(chuàng)建不一樣的決策樹,使貪婪算法能夠在建樹的同時(shí)評(píng)估每一個(gè)分裂點(diǎn)。這就是隨機(jī)森林算法(Random Forest algorithm)。

與裝袋算法一樣,隨機(jī)森林算法從訓(xùn)練集里擷取復(fù)合樣本并訓(xùn)練。其不同之處在于,數(shù)據(jù)在每個(gè)分裂點(diǎn)處完全分裂并添加到相應(yīng)的那棵決策樹當(dāng)中,且可以只考慮用于存儲(chǔ)屬性的某一固定子集。

對(duì)于分類問題,也就是本教程中我們將要探討的問題,其被考慮用于分裂的屬性數(shù)量被限定為小于輸入特征的數(shù)量之平方根。代碼如下:

num_features_for_split = sqrt(total_input_features)

這個(gè)小更改會(huì)讓生成的決策樹各不相同(沒有關(guān)聯(lián)),從而使得到的預(yù)測(cè)值更加多樣化。而多樣的預(yù)測(cè)值組合往往會(huì)比一棵單一的決策樹或者單一的裝袋算法有更優(yōu)的表現(xiàn)。 

聲納數(shù)據(jù)集(Sonar dataset)

我們將在本教程里使用聲納數(shù)據(jù)集作為輸入數(shù)據(jù)。這是一個(gè)描述聲納反射到不同物體表面后返回的不同數(shù)值的數(shù)據(jù)集。60 個(gè)輸入變量表示聲納從不同角度返回的強(qiáng)度。這是一個(gè)二元分類問題(binary classification problem),要求模型能夠區(qū)分出巖石和金屬柱體的不同材質(zhì)和形狀,總共有 208 個(gè)觀測(cè)樣本。

該數(shù)據(jù)集非常易于理解——每個(gè)變量都互有連續(xù)性且都在 0 到 1 的標(biāo)準(zhǔn)范圍之間,便于數(shù)據(jù)處理。作為輸出變量,字符串'M'表示金屬礦物質(zhì),'R'表示巖石。二者需分別轉(zhuǎn)換成整數(shù) 1 和 0。

通過預(yù)測(cè)數(shù)據(jù)集(M 或者金屬礦物質(zhì))中擁有最多觀測(cè)值的類,零規(guī)則算法(Zero Rule Algorithm)可實(shí)現(xiàn) 53% 的精確度。

更多有關(guān)該數(shù)據(jù)集的內(nèi)容可參見 UCI Machine Learning repository:https://archive.ics.uci.edu/ml/datasets/Connectionist+Bench+(Sonar,+Mines+vs.+Rocks)

免費(fèi)下載該數(shù)據(jù)集,將其命名為 sonar.all-data.csv,并存儲(chǔ)到需要被操作的工作目錄當(dāng)中。

教程

此次教程分為兩個(gè)步驟。

1. 分裂次數(shù)的計(jì)算。

2. 聲納數(shù)據(jù)集案例研究

這些步驟能讓你了解為你自己的預(yù)測(cè)建模問題實(shí)現(xiàn)和應(yīng)用隨機(jī)森林算法的基礎(chǔ)

1. 分裂次數(shù)的計(jì)算

在決策樹中,我們通過找到一些特定屬性和屬性的值來確定分裂點(diǎn),這類特定屬性需表現(xiàn)為其所需的成本是最低的。

分類問題的成本函數(shù)(cost function)通常是基尼指數(shù)(Gini index),即計(jì)算由分裂點(diǎn)產(chǎn)生的數(shù)據(jù)組的純度(purity)。對(duì)于這樣二元分類的分類問題來說,指數(shù)為 0 表示絕對(duì)純度,說明類值被完美地分為兩組。

從一棵決策樹中找到最佳分裂點(diǎn)需要在訓(xùn)練數(shù)據(jù)集中對(duì)每個(gè)輸入變量的值做成本評(píng)估。

在裝袋算法和隨機(jī)森林中,這個(gè)過程是在訓(xùn)練集的樣本上執(zhí)行并替換(放回)的。因?yàn)殡S機(jī)森林對(duì)輸入的數(shù)據(jù)要進(jìn)行行和列的采樣。對(duì)于行采樣,采用有放回的方式,也就是說同一行也許會(huì)在樣本中被選取和放入不止一次。

我們可以考慮創(chuàng)建一個(gè)可以自行輸入屬性的樣本,而不是枚舉所有輸入屬性的值以期找到獲取成本最低的分裂點(diǎn),從而對(duì)這個(gè)過程進(jìn)行優(yōu)化。

該輸入屬性樣本可隨機(jī)選取且沒有替換過程,這就意味著在尋找最低成本分裂點(diǎn)的時(shí)候每個(gè)輸入屬性只需被選取一次。

如下的代碼所示,函數(shù) get_split() 實(shí)現(xiàn)了上述過程。它將一定數(shù)量的來自待評(píng)估數(shù)據(jù)的輸入特征和一個(gè)數(shù)據(jù)集作為參數(shù),該數(shù)據(jù)集可以是實(shí)際訓(xùn)練集里的樣本。輔助函數(shù) test_split() 用于通過候選的分裂點(diǎn)來分割數(shù)據(jù)集,函數(shù) gini_index() 用于評(píng)估通過創(chuàng)建的行組(groups of rows)來確定的某一分裂點(diǎn)的成本。

以上我們可以看出,特征列表是通過隨機(jī)選擇特征索引生成的。通過枚舉該特征列表,我們可將訓(xùn)練集中的特定值評(píng)估為符合條件的分裂點(diǎn)。

# Select the best split point for a dataset
def get_split(dataset, n_features):
 class_values = list(set(row[-1] for row in dataset))
 b_index, b_value, b_score, b_groups = 999, 999, 999, None
 features = list()
 while len(features) < n_features:
  index = randrange(len(dataset[0])-1)
  if index not in features:
   features.append(index)
 for index in features:
  for row in dataset:
   groups = test_split(index, row[index], dataset)
   gini = gini_index(groups, class_values)
   if gini < b_score:
    b_index, b_value, b_score, b_groups = index, row[index], gini, groups
 return {'index':b_index, 'value':b_value, 'groups':b_groups}

至此,我們知道該如何改造一棵用于隨機(jī)森林算法的決策樹。我們可將之與裝袋算法結(jié)合運(yùn)用到真實(shí)的數(shù)據(jù)集當(dāng)中。

2. 關(guān)于聲納數(shù)據(jù)集的案例研究

在這個(gè)部分,我們將把隨機(jī)森林算法用于聲納數(shù)據(jù)集。本示例假定聲納數(shù)據(jù)集的 csv 格式副本已存在于當(dāng)前工作目錄中,文件名為 sonar.all-data.csv。

首先加載該數(shù)據(jù)集,將字符串轉(zhuǎn)換成數(shù)字,并將輸出列從字符串轉(zhuǎn)換成數(shù)值 0 和 1. 這個(gè)過程是通過輔助函數(shù) load_csv()、str_column_to_float() 和 str_column_to_int() 來分別實(shí)現(xiàn)的。

我們將通過 K 折交叉驗(yàn)證(k-fold cross validatio)來預(yù)估得到的學(xué)習(xí)模型在未知數(shù)據(jù)上的表現(xiàn)。這就意味著我們將創(chuàng)建并評(píng)估 K 個(gè)模型并預(yù)估這 K 個(gè)模型的平均誤差。評(píng)估每一個(gè)模型是由分類準(zhǔn)確度來體現(xiàn)的。輔助函數(shù) cross_validation_split()、accuracy_metric() 和 evaluate_algorithm() 分別實(shí)現(xiàn)了上述功能。

裝袋算法將通過分類和回歸樹算法來滿足。輔助函數(shù) test_split() 將數(shù)據(jù)集分割成不同的組;gini_index() 評(píng)估每個(gè)分裂點(diǎn);前文提及的改進(jìn)過的 get_split() 函數(shù)用來獲取分裂點(diǎn);函數(shù) to_terminal()、split() 和 build_tree() 用以創(chuàng)建單個(gè)決策樹;predict() 用于預(yù)測(cè);subsample() 為訓(xùn)練集建立子樣本集; bagging_predict() 對(duì)決策樹列表進(jìn)行預(yù)測(cè)。

新命名的函數(shù) random_forest() 首先從訓(xùn)練集的子樣本中創(chuàng)建決策樹列表,然后對(duì)其進(jìn)行預(yù)測(cè)。

正如我們開篇所說,隨機(jī)森林與決策樹關(guān)鍵的區(qū)別在于前者在建樹的方法上的小小的改變,這一點(diǎn)在運(yùn)行函數(shù) get_split() 得到了體現(xiàn)。

完整的代碼如下:

# Random Forest Algorithm on Sonar Dataset
from random import seed
from random import randrange
from csv import reader
from math import sqrt

# Load a CSV file
def load_csv(filename):
 dataset = list()
 with open(filename, 'r') as file:
  csv_reader = reader(file)
  for row in csv_reader:
   if not row:
    continue
   dataset.append(row)
 return dataset

# Convert string column to float
def str_column_to_float(dataset, column):
 for row in dataset:
  row[column] = float(row[column].strip())

# Convert string column to integer
def str_column_to_int(dataset, column):
 class_values = [row[column] for row in dataset]
 unique = set(class_values)
 lookup = dict()
 for i, value in enumerate(unique):
  lookup[value] = i
 for row in dataset:
  row[column] = lookup[row[column]]
 return lookup

# Split a dataset into k folds
def cross_validation_split(dataset, n_folds):
 dataset_split = list()
 dataset_copy = list(dataset)
 fold_size = len(dataset) / n_folds
 for i in range(n_folds):
  fold = list()
  while len(fold) < fold_size:
   index = randrange(len(dataset_copy))
   fold.append(dataset_copy.pop(index))
  dataset_split.append(fold)
 return dataset_split

# Calculate accuracy percentage
def accuracy_metric(actual, predicted):
 correct = 0
 for i in range(len(actual)):
  if actual[i] == predicted[i]:
   correct += 1
 return correct / float(len(actual)) * 100.0

# Evaluate an algorithm using a cross validation split
def evaluate_algorithm(dataset, algorithm, n_folds, *args):
 folds = cross_validation_split(dataset, n_folds)
 scores = list()
 for fold in folds:
  train_set =a list(folds)
  train_set.remove(fold)
  train_set = sum(train_set, [])
  test_set = list()
  for row in fold:
   row_copy = list(row)
   test_set.append(row_copy)
   row_copy[-1] = None
  predicted = algorithm(train_set, test_set, *args)
  actual = [row[-1] for row in fold]
  accuracy = accuracy_metric(actual, predicted)
  scores.append(accuracy)
 return scores

# Split a dataset based on an attribute and an attribute value
def test_split(index, value, dataset):
 left, right = list(), list()
 for row in dataset:
  if row[index] < value:
   left.append(row)
  else:
   right.append(row)
 return left, right

# Calculate the Gini index for a split dataset
def gini_index(groups, class_values):
 gini = 0.0
 for class_value in class_values:
  for group in groups:
   size = len(group)
   if size == 0:
    continue
   proportion = [row[-1] for row in group].count(class_value) / float(size)
   gini += (proportion * (1.0 - proportion))
 return gini

# Select the best split point for a dataset
def get_split(dataset, n_features):
 class_values = list(set(row[-1] for row in dataset))
 b_index, b_value, b_score, b_groups = 999, 999, 999, None
 features = list()
 while len(features) < n_features:
  index = randrange(len(dataset[0])-1)
  if index not in features:
   features.append(index)
 for index in features:
  for row in dataset:
   groups = test_split(index, row[index], dataset)
   gini = gini_index(groups, class_values)
   if gini < b_score:
    b_index, b_value, b_score, b_groups = index, row[index], gini, groups
 return {'index':b_index, 'value':b_value, 'groups':b_groups}

# Create a terminal node value
def to_terminal(group):
 outcomes = [row[-1] for row in group]
 return max(set(outcomes), key=outcomes.count)

# Create child splits for a node or make terminal
def split(node, max_depth, min_size, n_features, depth):
 left, right = node['groups']
 del(node['groups'])
 # check for a no split
 if not left or not right:
  node['left'] = node['right'] = to_terminal(left + right)
  return
 # check for max depth
 if depth >= max_depth:
  node['left'], node['right'] = to_terminal(left), to_terminal(right)
  return
 # process left child
 if len(left) <= min_size:
  node['left'] = to_terminal(left)
 else:
  node['left'] = get_split(left, n_features)
  split(node['left'], max_depth, min_size, n_features, depth+1)
 # process right child
 if len(right) <= min_size:
  node['right'] = to_terminal(right)
 else:
  node['right'] = get_split(right, n_features)
  split(node['right'], max_depth, min_size, n_features, depth+1)

# Build a decision tree
def build_tree(train, max_depth, min_size, n_features):
 root = get_split(dataset, n_features)
 split(root, max_depth, min_size, n_features, 1)
 return root

# Make a prediction with a decision tree
def predict(node, row):
 if row[node['index']] < node['value']:
  if isinstance(node['left'], dict):
   return predict(node['left'], row)
  else:
   return node['left']
 else:
  if isinstance(node['right'], dict):
   return predict(node['right'], row)
  else:
   return node['right']

# Create a random subsample from the dataset with replacement
def subsample(dataset, ratio):
 sample = list()
 n_sample = round(len(dataset) * ratio)
 while len(sample) < n_sample:
  index = randrange(len(dataset))
  sample.append(dataset[index])
 return sample

# Make a prediction with a list of bagged trees
def bagging_predict(trees, row):
 predictions = [predict(tree, row) for tree in trees]
 return max(set(predictions), key=predictions.count)

# Random Forest Algorithm
def random_forest(train, test, max_depth, min_size, sample_size, n_trees, n_features):
 trees = list()
 for i in range(n_trees):
  sample = subsample(train, sample_size)
  tree = build_tree(sample, max_depth, min_size, n_features)
  trees.append(tree)
 predictions = [bagging_predict(trees, row) for row in test]
 return(predictions)

# Test the random forest algorithm
seed(1)
# load and prepare data
filename = 'sonar.all-data.csv'
dataset = load_csv(filename)
# convert string attributes to integers
for i in range(0, len(dataset[0])-1):
 str_column_to_float(dataset, i)
# convert class column to integers
str_column_to_int(dataset, len(dataset[0])-1)
# evaluate algorithm
n_folds = 5
max_depth = 10
min_size = 1
sample_size = 1.0
n_features = int(sqrt(len(dataset[0])-1))
for n_trees in [1, 5, 10]:
 scores = evaluate_algorithm(dataset, random_forest, n_folds, max_depth, min_size, sample_size, n_trees, n_features)
 print('Trees: %d' % n_trees)
 print('Scores: %s' % scores)
  print('Mean Accuracy: %.3f%%' % (sum(scores)/float(len(scores))))

這里對(duì)第 197 行之后對(duì)各項(xiàng)參數(shù)的賦值做一個(gè)說明。

將 K 賦值為 5 用于交叉驗(yàn)證,得到每個(gè)子樣本為 208/5 = 41.6,即超過 40 條聲納返回記錄會(huì)用于每次迭代時(shí)的評(píng)估。

每棵樹的最大深度設(shè)置為 10,每個(gè)節(jié)點(diǎn)的最小訓(xùn)練行數(shù)為 1. 創(chuàng)建訓(xùn)練集樣本的大小與原始數(shù)據(jù)集相同,這也是隨機(jī)森林算法的默認(rèn)預(yù)期值。

我們把在每個(gè)分裂點(diǎn)需要考慮的特征數(shù)設(shè)置為總的特征數(shù)目的平方根,即 sqrt(60)=7.74,取整為 7。

將含有三組不同數(shù)量的樹同時(shí)進(jìn)行評(píng)估,以表明添加更多的樹可以使該算法實(shí)現(xiàn)的功能更多。

最后,運(yùn)行這個(gè)示例代碼將會(huì) print 出每組樹的相應(yīng)分值以及每種結(jié)構(gòu)的平均分值。如下所示:

Trees: 1
Scores: [68.29268292682927, 75.60975609756098, 70.73170731707317, 63.41463414634146, 65.85365853658537]
Mean Accuracy: 68.780%
 
Trees: 5
Scores: [68.29268292682927, 68.29268292682927, 78.04878048780488, 65.85365853658537, 68.29268292682927]
Mean Accuracy: 69.756%
 
Trees: 10
Scores: [68.29268292682927, 78.04878048780488, 75.60975609756098, 70.73170731707317, 70.73170731707317]
Mean Accuracy: 72.683%

擴(kuò)展

本節(jié)會(huì)列出一些與本次教程相關(guān)的擴(kuò)展內(nèi)容。大家或許有興趣一探究竟。

  • 算法調(diào)校(Algorithm Tuning)。本文所用的配置參數(shù)或有未被修正的錯(cuò)誤以及有待商榷之處。用更大規(guī)模的樹,不同的特征數(shù)量甚至不同的樹的結(jié)構(gòu)都可以改進(jìn)試驗(yàn)結(jié)果。
  • 更多問題。該方法同樣適用于其他的分類問題,甚至是用新的成本計(jì)算函數(shù)以及新的組合樹的預(yù)期值的方法使其適用于回歸算法。

回顧總結(jié)

通過本次教程的探討,你知道了隨機(jī)森林算法是如何實(shí)現(xiàn)的,特別是:

隨機(jī)森林與裝袋決策樹的區(qū)別。

如何用決策樹生成隨機(jī)森林算法。

如何將隨機(jī)森林算法應(yīng)用于解決實(shí)際操作中的預(yù)測(cè)模型問題。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python 2與Python 3版本和編碼的對(duì)比

    Python 2與Python 3版本和編碼的對(duì)比

    這篇文章主要介紹了Python 2與Python 3版本和編碼的對(duì)比,文中介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • python 定義函數(shù) 返回值只取其中一個(gè)的實(shí)現(xiàn)

    python 定義函數(shù) 返回值只取其中一個(gè)的實(shí)現(xiàn)

    這篇文章主要介紹了python 定義函數(shù) 返回值只取其中一個(gè)的實(shí)現(xiàn)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • 基于Python實(shí)現(xiàn)商場(chǎng)抽獎(jiǎng)小系統(tǒng)

    基于Python實(shí)現(xiàn)商場(chǎng)抽獎(jiǎng)小系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了如何利用Python語言實(shí)現(xiàn)一個(gè)簡(jiǎn)單的商場(chǎng)抽獎(jiǎng)小系統(tǒng),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2022-08-08
  • python去掉行尾的換行符方法

    python去掉行尾的換行符方法

    下面小編就為大家?guī)硪黄猵ython去掉行尾的換行符方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • python使用struct模塊實(shí)現(xiàn)打包/解包二進(jìn)制數(shù)據(jù)

    python使用struct模塊實(shí)現(xiàn)打包/解包二進(jìn)制數(shù)據(jù)

    因?yàn)榫W(wǎng)絡(luò)傳輸?shù)臄?shù)據(jù)都是二進(jìn)制字節(jié)流,而?Python?只有字符串可以直接轉(zhuǎn)成字節(jié)流,對(duì)于整數(shù)、浮點(diǎn)數(shù)則無能為力了,所以?Python?提供了?struct?模塊來幫我們解決這一點(diǎn),下面我們就來看看它的用法吧
    2023-09-09
  • python模塊的安裝以及安裝失敗的解決方法

    python模塊的安裝以及安裝失敗的解決方法

    Python 模塊(Module),是一個(gè) Python 文件,以 .py 結(jié)尾,包含了 Python 對(duì)象定義和Python語句。模塊讓你能夠有邏輯地組織你的 Python 代碼段。把相關(guān)的代碼分配到一個(gè)模塊里能讓你的代碼更好用,更易懂。模塊能定義函數(shù),類和變量,模塊里也能包含可執(zhí)行的代碼
    2021-11-11
  • python數(shù)據(jù)結(jié)構(gòu)之搜索講解

    python數(shù)據(jù)結(jié)構(gòu)之搜索講解

    這篇文章主要介紹了python數(shù)據(jù)結(jié)構(gòu)之搜索講解,搜索是指從元素集合中找到某個(gè)特定元素的算法過程。搜索過程通常返回?True?或?False,?分別表示元素是否存在,下面一起來了解文章的詳細(xì)內(nèi)容吧,希望對(duì)你有所幫助
    2021-12-12
  • 解決django前后端分離csrf驗(yàn)證的問題

    解決django前后端分離csrf驗(yàn)證的問題

    今天小編就為大家分享一篇解決django前后端分離csrf驗(yàn)證的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-02-02
  • Anaconda安裝pytorch及配置PyCharm 2021環(huán)境

    Anaconda安裝pytorch及配置PyCharm 2021環(huán)境

    小編使用的是python3.8版本,為了防止訪問量過大導(dǎo)致http連接失敗,所以采用本地安裝,具體安裝方法本文給大家詳細(xì)介紹,在文章底部給大家提到了PyCharm 2021配置環(huán)境的方法,感興趣的朋友一起看看吧
    2021-06-06
  • python實(shí)現(xiàn)將JSON文件中的數(shù)據(jù)格式化處理

    python實(shí)現(xiàn)將JSON文件中的數(shù)據(jù)格式化處理

    JSON是一種輕量級(jí)的數(shù)據(jù)交換格式,常用于Web服務(wù)間的數(shù)據(jù)傳輸,Python內(nèi)置了??json??模塊,能夠方便地進(jìn)行JSON數(shù)據(jù)的解析與格式化,本文將通過具體的Python代碼實(shí)例,深入探討如何將JSON文件中的數(shù)據(jù)進(jìn)行格式化處理,需要的朋友可以參考下
    2024-03-03

最新評(píng)論

深水埗区| 南江县| 台南市| 镇巴县| 临安市| 兴海县| 石景山区| 景德镇市| 龙南县| 广元市| 金平| 大渡口区| 运城市| 聊城市| 都江堰市| 萨嘎县| 宁化县| 铜陵市| 中卫市| 理塘县| 长乐市| 凤阳县| 买车| 昌黎县| 花莲县| 江西省| 林甸县| 临高县| 德化县| 麦盖提县| 黑河市| 岳池县| 镇巴县| 南阳市| 金秀| 鱼台县| 龙泉市| 华容县| 遵化市| 土默特右旗| 无为县|