【機器學習實戰】Datawhale夏令營:Baseline精讀筆記2

# AI夏令營 # Datawhale # 夏令營

在原有的Baseline上除了交叉驗證,還有一種關鍵的優化方式,即特征工程。

如何優化特征,關系著我們提高模型預測的精準度。特征工程往往是對問題的領域有深入了解的人員能夠做好的部分,因為我們要思考轉換的方式。

Smiles特征之外還有很多特征可以提取有價值的信息,比如InChI是由一系列部分組成,提供了關于分子結構的詳細信息。比如開頭標識、分子式、連接表、氫原子計數、多可旋轉鍵計數、立體化學信息、同分異構體信息、混合物或互變異構體信息、電荷和自旋多重度信息等。

除此之外,要想提升模型的精準度,換模型也未嘗不可。

特征優化

提取分子式

從InChI字符串中,我們可以看到分子式直接給出在/C47H61N7O6S部分。這意味著分子由47個碳原子、61個氫原子、7個氮原子、6個氧原子和1個硫原子組成;

計算分子量

分子量可以通過將每種原子的原子質量乘以其數量然后相加得到。

  • 碳(C)的原子質量約為12.01 g/mol

  • 氫(H)的原子質量約為1.008 g/mol

  • 氮(N)的原子質量約為14.01 g/mol

  • 氧(O)的原子質量約為16.00 g/mol

  • 硫(S)的原子質量約為32.07 g/mol

乘以數量相加,我們就可以得到分子量。

原子計數

直接計算不同原子的個數,并進行展開。

import pandas as pd
import reatomic_masses = {'H': 1.008, 'He': 4.002602, 'Li': 6.94, 'Be': 9.0122, 'B': 10.81, 'C': 12.01,'N': 14.01, 'O': 16.00, 'F': 19.00, 'Ne': 20.180, 'Na': 22.990, 'Mg': 24.305,'Al': 26.982, 'Si': 28.085, 'P': 30.97, 'S': 32.07, 'Cl': 35.45, 'Ar': 39.95,'K': 39.10, 'Ca': 40.08, 'Sc': 44.956, 'Ti': 47.867, 'V': 50.942, 'Cr': 52.00,'Mn': 54.938, 'Fe': 55.845, 'Co': 58.933, 'Ni': 58.69, 'Cu': 63.55, 'Zn': 65.38
}# 函數用于解析單個InChI字符串
def parse_inchi(row):inchi_str = row['InChI']formula = ''molecular_weight = 0element_counts = {}# 提取分子式formula_match = re.search(r"InChI=1S/([^/]+)/c", inchi_str)if formula_match:formula = formula_match.group(1)# 計算分子量和原子計數for element, count in re.findall(r"([A-Z][a-z]*)([0-9]*)", formula):count = int(count) if count else 1element_mass = atomic_masses.get(element.upper(), 0)molecular_weight += element_mass * countelement_counts[element.upper()] = countreturn pd.Series({'Formula': formula,'MolecularWeight': molecular_weight,'ElementCounts': element_counts})# 應用函數到DataFrame的每一行
train[['Formula', 'MolecularWeight', 'ElementCounts']] = train.apply(parse_inchi, axis=1)# 定義存在的key
keys = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn']# 創建一個空的DataFrame,列名為keys
df_expanded = pd.DataFrame({key: pd.Series() for key in keys})# 遍歷數據,填充DataFrame
for index, item in enumerate(train['ElementCounts'].values):for key in keys:# 將字典中的值填充到相應的列中df_expanded.at[index, key] = item.get(key, 0)df_expanded = pd.DataFrame(df_expanded)

模型融合

上次提到了我們使用的是catboost模型,沒有嘗試過lightgbm和xgboost,可以依次跑完這三個模型,然后對三個模型的結果進行取平均進行融合(也是可以改進的地方)。

def cv_model(clf, train_x, train_y, test_x, clf_name, seed = 2023):folds = 5kf = KFold(n_splits=folds, shuffle=True, random_state=seed)oof = np.zeros(train_x.shape[0])test_predict = np.zeros(test_x.shape[0])cv_scores = []for i, (train_index, valid_index) in enumerate(kf.split(train_x, train_y)):print('************************************ {} ************************************'.format(str(i+1)))trn_x, trn_y, val_x, val_y = train_x.iloc[train_index], train_y[train_index], train_x.iloc[valid_index], train_y[valid_index]if clf_name == "lgb":train_matrix = clf.Dataset(trn_x, label=trn_y)valid_matrix = clf.Dataset(val_x, label=val_y)params = {'boosting_type': 'gbdt','objective': 'binary','min_child_weight': 6,'num_leaves': 2 ** 6,'lambda_l2': 10,'feature_fraction': 0.8,'bagging_fraction': 0.8,'bagging_freq': 4,'learning_rate': 0.35,'seed': 2024,'nthread' : 16,'verbose' : -1,}model = clf.train(params, train_matrix, 2000, valid_sets=[train_matrix, valid_matrix],categorical_feature=[], verbose_eval=1000, early_stopping_rounds=100)val_pred = model.predict(val_x, num_iteration=model.best_iteration)test_pred = model.predict(test_x, num_iteration=model.best_iteration)if clf_name == "xgb":xgb_params = {'booster': 'gbtree', 'objective': 'binary:logistic','num_class':3,'max_depth': 5,'lambda': 10,'subsample': 0.7,'colsample_bytree': 0.7,'colsample_bylevel': 0.7,'eta': 0.35,'tree_method': 'hist','seed': 520,'nthread': 16}train_matrix = clf.DMatrix(trn_x , label=trn_y)valid_matrix = clf.DMatrix(val_x , label=val_y)test_matrix = clf.DMatrix(test_x)watchlist = [(train_matrix, 'train'),(valid_matrix, 'eval')]model = clf.train(xgb_params, train_matrix, num_boost_round=2000, evals=watchlist, verbose_eval=1000, early_stopping_rounds=100)val_pred  = model.predict(valid_matrix)test_pred = model.predict(test_matrix)if clf_name == "cat":params = {'learning_rate': 0.35, 'depth': 5, 'bootstrap_type':'Bernoulli','random_seed':2024,'od_type': 'Iter', 'od_wait': 100, 'random_seed': 11, 'allow_writing_files': False}model = clf(iterations=2000, **params)model.fit(trn_x, trn_y, eval_set=(val_x, val_y),metric_period=1000,use_best_model=True, cat_features=[],verbose=1)val_pred  = model.predict_proba(val_x)test_pred = model.predict_proba(test_x)oof[valid_index] = val_predtest_predict += test_pred / kf.n_splitsF1_score = f1_score(val_y, np.where(val_pred>0.5, 1, 0))cv_scores.append(F1_score)print(cv_scores)return oof, test_predict# 參考demo,具體對照baseline實踐部分調用cv_model函數
# 選擇lightgbm模型
lgb_oof, lgb_test = cv_model(lgb, x_train, y_train, x_test, 'lgb')
# 選擇xgboost模型
xgb_oof, xgb_test = cv_model(xgb, x_train, y_train, x_test, 'xgb')
# 選擇catboost模型
cat_oof, cat_test = cv_model(CatBoostClassifier, x_train, y_train, x_test, 'cat')# 進行取平均融合
final_test = (lgb_test + xgb_test + cat_test) / 3

或者可以用stacking的方法

代碼更正

要想在飛槳上跑數據,復制粘貼是不行的。由于部分模型版本更迭,下面給出完整的更正后代碼。

import numpy as np
import pandas as pd
from catboost import CatBoostClassifier
from sklearn.model_selection import StratifiedKFold, KFold, GroupKFold
from sklearn.metrics import f1_score
from rdkit import Chem
from rdkit.Chem import Descriptors
from sklearn.feature_extraction.text import TfidfVectorizer
import tqdm, sys, os, gc, re, argparse, warnings
warnings.filterwarnings('ignore')train = pd.read_excel('./data/data280993/traindata-new.xlsx')
test = pd.read_excel('./data/data280993/testdata-new.xlsx')# test數據不包含 DC50 (nM) 和 Dmax (%)
train = train.drop(['DC50 (nM)', 'Dmax (%)'], axis=1)# 定義了一個空列表drop_cols,用于存儲在測試數據集中非空值小于10個的列名。
drop_cols = []
for f in test.columns:if test[f].notnull().sum() < 10:drop_cols.append(f)# 使用drop方法從訓練集和測試集中刪除了這些列,以避免在后續的分析或建模中使用這些包含大量缺失值的列
train = train.drop(drop_cols, axis=1)
test = test.drop(drop_cols, axis=1)# 使用pd.concat將清洗后的訓練集和測試集合并成一個名為data的DataFrame,便于進行統一的特征工程處理
data = pd.concat([train, test], axis=0, ignore_index=True)
cols = data.columns[2:]# 將SMILES轉換為分子對象列表,并轉換為SMILES字符串列表
data['smiles_list'] = data['Smiles'].apply(lambda x:[Chem.MolToSmiles(mol, isomericSmiles=True) for mol in [Chem.MolFromSmiles(x)]])
data['smiles_list'] = data['smiles_list'].map(lambda x: ' '.join(x))  # 使用TfidfVectorizer計算TF-IDF
tfidf = TfidfVectorizer(max_df = 0.9, min_df = 1, sublinear_tf = True)
res = tfidf.fit_transform(data['smiles_list'])# 將結果轉為dataframe格式
tfidf_df = pd.DataFrame(res.toarray())
tfidf_df.columns = [f'smiles_tfidf_{i}' for i in range(tfidf_df.shape[1])]# 按列合并到data數據
data = pd.concat([data, tfidf_df], axis=1)# 自然數編碼
def label_encode(series):unique = list(series.unique())return series.map(dict(zip(unique, range(series.nunique()))))for col in cols:if data[col].dtype == 'object':data[col]  = label_encode(data[col])train = data[data.Label.notnull()].reset_index(drop=True)
test = data[data.Label.isnull()].reset_index(drop=True)

lgb不支持特殊字符的輸入,因此我們需要重寫特征名稱:

import redef strict_clean_feature_name(name):# 只保留字母、數字和下劃線name = re.sub(r'[^a-zA-Z0-9_]', '', name)# 確保名稱不為空,并且不以數字開頭if not name or name[0].isdigit():name = 'f_' + namereturn name# 應用新的清理函數
x_train.columns = [strict_clean_feature_name(col) for col in x_train.columns]
x_test.columns = [strict_clean_feature_name(col) for col in x_test.columns]# 再次檢查清理后的特征名稱
print(x_train.columns)

模型融合:

import lightgbm as lgb
import xgboost as xgb
from catboost import CatBoostClassifieratomic_masses = {'H': 1.008, 'He': 4.002602, 'Li': 6.94, 'Be': 9.0122, 'B': 10.81, 'C': 12.01,'N': 14.01, 'O': 16.00, 'F': 19.00, 'Ne': 20.180, 'Na': 22.990, 'Mg': 24.305,'Al': 26.982, 'Si': 28.085, 'P': 30.97, 'S': 32.07, 'Cl': 35.45, 'Ar': 39.95,'K': 39.10, 'Ca': 40.08, 'Sc': 44.956, 'Ti': 47.867, 'V': 50.942, 'Cr': 52.00,'Mn': 54.938, 'Fe': 55.845, 'Co': 58.933, 'Ni': 58.69, 'Cu': 63.55, 'Zn': 65.38
}def parse_inchi(row):inchi_str = row['InChI']  # Assuming 'InChI' is a column in your DataFrameif isinstance(inchi_str, str):  # Check if inchi_str is a stringformula_match = re.search(r"InChI=1S/([^/]+)/c", inchi_str)if formula_match:formula = formula_match.group(1)molecular_weight = calculate_molecular_weight(formula)  # You need to define this functionelement_counts = extract_element_counts(formula)  # You need to define this functionreturn pd.Series({'Formula': formula,'MolecularWeight': molecular_weight,'ElementCounts': element_counts})else:# Handle case where regex pattern does not matchreturn pd.Series({'Formula': None,'MolecularWeight': None,'ElementCounts': None})else:# Handle case where inchi_str is not a string (e.g., it could be None or unexpected type)return pd.Series({'Formula': None,'MolecularWeight': None,'ElementCounts': None})# 應用函數到DataFrame的每一行
train[['Formula', 'MolecularWeight', 'ElementCounts']] = train.apply(parse_inchi, axis=1)# 定義存在的key
keys = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn']# 創建一個空的DataFrame,列名為keys
df_expanded = pd.DataFrame({key: pd.Series() for key in keys})for index, item in enumerate(train['ElementCounts'].values):if item is not None:for key in keys:# 將字典中的值填充到相應的列中df_expanded.at[index, key] = item.get(key, 0)else:# 如果 item 是 None,則所有元素計數設為 0for key in keys:df_expanded.at[index, key] = 0
df_expanded = pd.DataFrame(df_expanded)def cv_model(clf, train_x, train_y, test_x, clf_name, seed = 2023):folds = 5kf = KFold(n_splits=folds, shuffle=True, random_state=seed)oof = np.zeros(train_x.shape[0])test_predict = np.zeros(test_x.shape[0])cv_scores = []for i, (train_index, valid_index) in enumerate(kf.split(train_x, train_y)):print('************************************ {} ************************************'.format(str(i+1)))trn_x, trn_y, val_x, val_y = train_x.iloc[train_index], train_y[train_index], train_x.iloc[valid_index], train_y[valid_index]if clf_name == "lgb":train_matrix = clf.Dataset(trn_x, label=trn_y)valid_matrix = clf.Dataset(val_x, label=val_y)params = {'boosting_type': 'gbdt','objective': 'binary','min_child_weight': 6,'num_leaves': 2 ** 6,'lambda_l2': 10,'feature_fraction': 0.8,'bagging_fraction': 0.8,'bagging_freq': 4,'learning_rate': 0.35,'seed': 2024,'verbose': -1,}model = clf.train(params,train_matrix,num_boost_round=2000,valid_sets=[train_matrix, valid_matrix],categorical_feature=[],callbacks=[lgb.early_stopping(stopping_rounds=100),lgb.log_evaluation(period=1000)])val_pred = model.predict(val_x, num_iteration=model.best_iteration)test_pred = model.predict(test_x, num_iteration=model.best_iteration)if clf_name == "xgb":xgb_params = {'booster': 'gbtree', 'objective': 'binary:logistic','num_class':3,'max_depth': 5,'lambda': 10,'subsample': 0.7,'colsample_bytree': 0.7,'colsample_bylevel': 0.7,'eta': 0.35,'tree_method': 'hist','seed': 520,'nthread': 16}train_matrix = clf.DMatrix(trn_x , label=trn_y)valid_matrix = clf.DMatrix(val_x , label=val_y)test_matrix = clf.DMatrix(test_x)watchlist = [(train_matrix, 'train'),(valid_matrix, 'eval')]model = clf.train(xgb_params, train_matrix, num_boost_round=2000, evals=watchlist, verbose_eval=1000, early_stopping_rounds=100)val_pred  = model.predict(valid_matrix)test_pred = model.predict(test_matrix)if clf_name == "cat":params = {'learning_rate': 0.35, 'depth': 5, 'bootstrap_type':'Bernoulli','random_seed':2024,'od_type': 'Iter', 'od_wait': 100, 'random_seed': 11, 'allow_writing_files': False}model = clf(iterations=2000, **params)model.fit(trn_x, trn_y, eval_set=(val_x, val_y),metric_period=1000,use_best_model=True, cat_features=[],verbose=1)val_pred  = model.predict_proba(val_x)test_pred = model.predict_proba(test_x)oof[valid_index] = val_predtest_predict += test_pred / kf.n_splitsF1_score = f1_score(val_y, np.where(val_pred>0.5, 1, 0))cv_scores.append(F1_score)print(cv_scores)return oof, test_predict# 參考demo,具體對照baseline實踐部分調用cv_model函數
# 選擇lightgbm模型
lgb_oof, lgb_test = cv_model(lgb, x_train, y_train, x_test, 'lgb')
# 選擇xgboost模型
xgb_oof, xgb_test = cv_model(xgb, x_train, y_train, x_test, 'xgb')
# 選擇catboost模型
cat_oof, cat_test = cv_model(CatBoostClassifier, x_train, y_train, x_test, 'cat')# 進行取平均融合
final_test = (lgb_test + xgb_test + cat_test) / 3

跑的比較慢。

Stacking

def stack_model(oof_1, oof_2, oof_3, predictions_1, predictions_2, predictions_3, y):'''輸入的oof_1, oof_2, oof_3可以對應lgb_oof,xgb_oof,cat_oofpredictions_1, predictions_2, predictions_3對應lgb_test,xgb_test,cat_test'''train_stack = pd.concat([oof_1, oof_2, oof_3], axis=1)test_stack = pd.concat([predictions_1, predictions_2, predictions_3], axis=1)oof = np.zeros((train_stack.shape[0],))predictions = np.zeros((test_stack.shape[0],))scores = []from sklearn.model_selection import RepeatedKFoldfolds = RepeatedKFold(n_splits=5, n_repeats=2, random_state=2021)for fold_, (trn_idx, val_idx) in enumerate(folds.split(train_stack, train_stack)): print("fold n°{}".format(fold_+1))trn_data, trn_y = train_stack.loc[trn_idx], y[trn_idx]val_data, val_y = train_stack.loc[val_idx], y[val_idx]clf = Ridge(random_state=2024)clf.fit(trn_data, trn_y)oof[val_idx] = clf.predict(val_data)predictions += clf.predict(test_stack) / (5 * 2)score_single = roc_auc_score(val_y, oof[val_idx])scores.append(score_single)print(f'{fold_+1}/{5}', score_single)print('mean: ',np.mean(scores))return oof, predictions

它接受之前三個模型傳入的參數。

在這里插入圖片描述

stacking是一種分層模型集成框架。以兩層為例,第一層由多個基學習器組成,其輸入為原始訓練集,第二層的模型則是以第一層基學習器的輸出作為特征加入訓練集進行再訓練,從而得到完整的stacking模型。

第一層和k折交叉驗證類似,取平均,第二層stacking,將訓練集中的四個標簽外加真實標簽當作五列新的特征作為新的訓練集,選取一個訓練模型,根據新的訓練集進行訓練,然后應用測試集的四個標簽組成的測試集進行預測作為最終的result。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/41458.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/41458.shtml
英文地址,請注明出處:http://en.pswp.cn/web/41458.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

鏈式二叉樹oj題

1.輸入k &#xff0c;找第k層節點個數 int TreeKlevel(BTNode*root,int k) {if (root NULL) {return 0;}if (k 1) {return 1;}return TreeKlevel(root->left, k - 1)TreeKlevel(root->right, k - 1); } 在這里我們要確定遞歸子問題&#xff0c;第一個就是NULL時返回&…

26_嵌入式系統網絡接口

以太網接口基本原理 IEEE802標準 局域網標準協議工作在物理層和數據鏈路層&#xff0c;其將數據鏈路層又劃分為兩層&#xff0c;從下到上分別為介質訪問控制子層(不同的MAC子層&#xff0c;與具體接入的傳輸介質相關),邏輯鏈路控制子層(統一的LLC子層&#xff0c;為上層提供統…

非同步升壓轉換器,效率95%你信嗎?ETA1611輸出電流2A, 22V DCDC

前言&#xff1a; 截止24年7月7日某創報價&#xff1a;500&#xff1a; &#xffe5;0.7856 / 個 建議使用前同時了解下方器件。 2毛錢的SOT23-5封裝28V、1.5A、1.2MHz DCDC轉換器用于LCD偏置電源和白光LED驅動等MT3540升壓芯片 描述 ETA1611 SOT23-6封裝 絲印GVYW&#xff0…

c進階篇(三):字符串函數

1.strlen: strlen - C Reference strlen 函數是一個標準庫函數&#xff0c;用于計算以 null 結尾的字符串的長度&#xff0c;也就是字符串中實際字符的數量&#xff0c;不包括最后的 null 終止符 \0。它定義在 <string.h> 頭文件中。 函數原型:size_t strlen(const ch…

一篇就夠了,為你答疑解惑:鋰電池一階模型-在線參數辨識(附代碼)

鋰電池一階模型-在線參數辨識 背景在線 VS 離線 參數辨識遞推最小二乘法一階戴維南Z域離散表達式 背景 鋰電池一階戴維南等效模型的基礎知識和離線辨識方法&#xff0c;已經在上一期非常詳細地講解了一輪&#xff08;上期文章請戳此處&#xff09;&#xff0c;本期繼續講解一下…

【數據結構】經典鏈表題目詳解集合(反轉鏈表、相交鏈表、鏈表的中間節點、回文鏈表)

文章目錄 一、反轉鏈表1、程序詳解2、代碼 二、相交鏈表1、程序詳解2、代碼 三、鏈表的中間節點1、程序詳解2、代碼 四、回文鏈表1、程序詳解2、代碼 一、反轉鏈表 1、程序詳解 題目&#xff1a;給定單鏈表的頭節點 head &#xff0c;請反轉鏈表&#xff0c;并返回反轉后的鏈…

理解注意力機制與多頭注意力:深度學習中的“聚焦術”

Attention 理解注意力機制與多頭注意力&#xff1a;深度學習中的“聚焦術”什么是注意力機制&#xff1f;**核心思想** 什么是多頭注意力機制&#xff1f;**工作原理** **多頭注意力的優勢****應用領域****結論** 理解注意力機制與多頭注意力&#xff1a;深度學習中的“聚焦術”…

MLIR

方言 簡介操作塊區域值范圍Control Flow and SSACFG Regions 操作與多區域&#xff08;Operations with Multiple Regions&#xff09;閉包&#xff08;Closure&#xff09;圖形區域&#xff08;Graph Regions&#xff09;參數和結果&#xff08;Arguments and Results&#xf…

vscode編輯keil工程

1.編碼問題 通常keil默認amsi格式&#xff0c;vscode默認utf-8格式&#xff0c;直接打開會出現亂碼問題。 解決過程&#xff1a; 1.想著創建keil階段&#xff0c;就使用utf-編碼格式。 在區域設置里面“選擇beta版&#xff0c;提供全球utf-8 提供全球語言支持”&#xff0c…

JVM專題之內存模型以及如何判定對象已死問題

體驗與驗證 2.4.5.1 使用visualvm **visualgc插件下載鏈接 :https://visualvm.github.io/pluginscenters.html https://visualvm.github.io/pluginscenters.html **選擇對應JDK版本鏈接--->Tools--->Visual GC** 2.4.5.2 堆內存溢出 * **代碼** java @RestCont…

從0制作自己的ros導航小車(01、準備工作)

@TOC 前言 本篇說明需要具備的知識和軟硬件。可以不用全部具備,但基礎要有,寫的不是非常詳細。 本小車分為上位機與下位機兩部分,上位機使用旭日x3派運行ros進行開發和算法實現,下位機使用stm32驅動底盤和傳感器數據采集。 一、知識 ①stm32部分(當然也可以使用其它控制…

uniapp/Android App上架三星市場需要下載所需要的SDK

只需添加以下一個權限在AndroidManifest.xml <uses-permission android:name"com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY"/>uniapp開發的&#xff0c;需要在App權限配置中加入以上的額外權限&#xff1a;

1958.力扣每日一題7/7 Java(100%解)

博客主頁&#xff1a;音符猶如代碼系列專欄&#xff1a;算法練習關注博主&#xff0c;后期持續更新系列文章如果有錯誤感謝請大家批評指出&#xff0c;及時修改感謝大家點贊&#x1f44d;收藏?評論? 目錄 思路 解題方法 時間復雜度 空間復雜度 Code 思路 首先將指定位…

游戲開發面試題5

什么是進程、線程、協程 進程 進程是計算機的一種基本運行單位&#xff0c;由操作系統管理資源和分配資源的基本單位&#xff0c;進程可以理解為一個正在運行的程序 線程 線程是計算機的一種獨立執行單元&#xff0c;是操作系統能夠進行運算調度的基本單位&#xff0c;線程之間…

排序 -- 手撕歸并排序(遞歸和非遞歸寫法)

一、基本思想 歸并排序&#xff08;MERGE-SORT&#xff09;是建立在歸并操作上的一種有效的排序算法,該算法是采用分治法&#xff08;Divide and Conquer&#xff09;的一個非常典型的應用。將已有序的子序列合并&#xff0c;得到完全有序的序列&#xff1b;即先使每個子序列有…

漢諾塔與青蛙跳臺階

1.漢諾塔 根據漢諾塔 - 維基百科 介紹 1.1 背景 最早發明這個問題的人是法國數學家愛德華盧卡斯。 傳說越南河內某間寺院有三根銀棒&#xff0c;上串 64 個金盤。寺院里的僧侶依照一個古老的預言&#xff0c;以上述規則移動這些盤子&#xff1b;預言說當這些盤子移動完畢&am…

SpringMVC(2)——controller方法參數與html表單對應

controller方法參數與html表單對應 0. User實體類 import org.springframework.format.annotation.DateTimeFormat;import java.io.Serializable; import java.util.Date; import java.util.List; import java.util.Map;public class User implements Serializable {private …

ES7210高性能四通道音頻ADC轉換模擬麥克風為IIS數字咪頭

特征 高性能多位 Delta-Σ 音頻 ADC 102 dB 信噪比 -85 分貝 THDN 24 位&#xff0c;8 至 100 kHz 采樣頻率 I2S/PCM 主串行數據端口或從串行數據端口 支持TDM 256/384Fs、USB 12/24 MHz 和其他非標準音頻系統時鐘 低功耗待機模式 應用 麥克風陣列 智能音箱 遠場語音捕獲 訂購…

微服務的分布式事務解決方案

微服務的分布式事務解決方案 1、分布式事務的理論模型1.1、X/Open 分布式事務模型1.2、兩階段提交協議1.3、三階段提交協議 2、分布式事務常見解決方案2.1、TCC補償型方案2.2、基于可靠性消息的最終一致性方案2.3、最大努力通知型方案 3、分布式事務中間件 Seata3.1、AT 模式3.…

人工智能在軟件開發中的角色:助手還是取代者?

人工智能在軟件開發中的角色&#xff1a;助手還是取代者&#xff1f; 隨著科技的飛速發展&#xff0c;生成式人工智能&#xff08;AIGC&#xff09;在軟件開發領域的應用越來越廣泛。從代碼生成、錯誤檢測到自動化測試&#xff0c;AI工具正成為開發者的重要助手。然而&#xf…