0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

matminerでマテリアルズインフォマティックス(2) データセットを前処理

Last updated at Posted at 2025-04-13

簡単に使えそうなデータは・・

まずはテーブルで簡単に使えそうなデータを探してみました。
Materials Projectのデータを元にしたmatbenchにある鋼材の元素組成と強度のデータがあります。

from matminer.datasets import load_dataset
df = load_dataset("matbench_steels")
print(df)

matminerで簡単にpandasのデータフレームに保存はできるのですが、こういう形で保存されます。

print(df.head(3))
composition yield strength
Fe0.620C0.000953Mn0.000521Si0.00102Cr0.000110N.. 2411.5
Fe0.623C0.00854Mn0.000104Si0.000203Cr0.147Ni0.... 1736.3

組成のところに、元素と組成比が文字列で入っています。これを元素別に組成の表を作る必要があります。

データの前処理

import re
import pandas as pd

def extract_value(composition_string,element_name):
    pattern = r'{}(\d+\.?\d*)'.format(element_name)
    match = re.search(pattern, composition_string)
    if match:
        return float(match.group(1))
    else:
        return 0.0

elements = ["Fe","C","Mn","Si","Cr","Ni","Mo","V","N","Nb","Co","W","Al","Ti"]

for i in elements:
    comp_values = []
    for composition in df['composition']:

        value = extract_value(composition,i)
        comp_values.append(value)
        df[i] = pd.Series(comp_values)
print(df)

正規表現で、元素の文字列の次の数値を取り出す関数extract_valueを作りました。
元素の文字列を渡して、その元素の後ろにある数値を取り出していきます。

これで取り出すと次のような元素組成のデータが取り出せます。

yield strength Fe C Mn Si Cr Ni
2411.5 0.62 0.000953 0.000521 0.00102 0.00011 0.192
1736.3 0.623 0.00854 0.000104 0.000203 0.147 9.71E-05

これで、元素組成から降伏強度を予測する準備ができました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?