Predict[{in1out1,in2out2,…}]
例 iniから outiを予測しようとするPredictorFunctionを生成する.
Predict[data,input]
与えられた訓練例から input に関連付けられた出力を予測しようとする.
Predict[data,input,prop]
指定された特性 prop を予測と相対的に計算する.
Predict
Predict[{in1out1,in2out2,…}]
例 iniから outiを予測しようとするPredictorFunctionを生成する.
Predict[data,input]
与えられた訓練例から input に関連付けられた出力を予測しようとする.
Predict[data,input,prop]
指定された特性 prop を予測と相対的に計算する.
詳細とオプション
- Predictは,数値,テキスト,サウンド,画像等を含むさまざまなタイプのデータとスカラー変数との間の関係をモデル化するために使われる.
- この種のモデリングは,回帰分析としても知られるもので,顧客の行動分析,医療成果の予測,信用リスク評価等によく使われる.
- 複雑な式は,数やクラスのようにより単純な特徴に自動的に変換される.
- 最終的なモデルタイプとハイパーパラメータ値は,訓練データについてのクロス確認を使って選択される.
- 以下は,使用可能な訓練 data の構造である.
-
{in1out1,in2out2,…} 入力と出力の間のRuleのリスト {in1,in2,…}{out1,out2,…} 入力と対応する出力の間のRule {list1,list2,…}n 出力としての各Listの n 番目の要素 {assoc1,assoc2,…}"key" 入力としての各Associationの"key"要素 Dataset[…]column 出力としてのDatasetの指定された column Tabular[…]column 出力としてのTabularの指定された column - これに加え,data の特殊形には以下が含まれる.
-
"name" 組込みの予測関数 FittedModel[…] PredictorFunction[…]に変換されたフィットモデル - 各例の入力 iniは,単一のデータ要素,リスト{feature1, …},あるいは連想<|"feature1"value1,…|>でよい.
- 各例の出力 outiは数値でなければならない.
- 予測特性 prop はPredictorFunctionと同じである.以下はその例である.
-
"Decision" 分布と効用関数に基づく最良の予測 "Distribution" 入力を条件とする値の分布 "SHAPValues" 各例のシャープレイ追加特徴の説明 "SHAPValues"n n 個のサンプルを使ったSHAPの説明 "Properties" 使用可能な全特性のリスト - "SHAPValues"は,さまざまな特徴を削除し次に合成した結果の予測を比較することで特徴の貢献度を評価する.オプションMissingValueSynthesisを使って欠測値を合成する方法が指定できる.SHAPの説明は訓練出力の平均からの偏差として与えられる.
- 次は,組込みの予測器関数の例である.
-
"NameAge" 名前を与えられた場合の人の年齢 - 次は,使用可能なオプションである.
-
AnomalyDetector None 予測器が使う異常検出器 AcceptanceThreshold Automatic 異常検出器の稀少確率閾値 FeatureExtractor Identity 学習対象となる特徴をどのように抽出するか FeatureNames Automatic 入力データに割り当てる特徴の名前 FeatureTypes Automatic 入力データに仮定する特徴タイプ IndeterminateThreshold 0 どの確率密度より下でIndeterminateを返すか Method Automatic 使用する回帰アルゴリズム MissingValueSynthesis Automatic 欠測値の合成方法 PerformanceGoal Automatic パフォーマンスのどの面について最適化するか RecalibrationFunction Automatic 予測された値をどのように後処理するか RandomSeeding 1234 どのような擬似乱数生成器のシードを内部的に使うべきか TargetDevice "CPU" そこで訓練を行うターゲットデバイス TimeGoal Automatic 分類器の訓練にどのくらい時間をかけるか TrainingProgressReporting Automatic 訓練中の進捗状況をどのようにレポートするか UtilityFunction Automatic 実測値/予測値の関数としての効用 ValidationSet Automatic 生成されたモデルを確かめるためのデータ - FeatureExtractor"Minimal"は内部の前処理を出来るだけ簡単にすべきであることを示す.
- 次は,Methodの可能な設定値である.
-

"DecisionTree" 決定木を使って予測する 
"GradientBoostedTrees" 勾配ブースティングで訓練した木の集合を使って予測する 
"LinearRegression" 特徴の線形結合から予測する 
"NearestNeighbors" 最近傍の例から予測する 
"NeuralNetwork" 人工の神経回路網を使って予測する 
"RandomForest" 決定木についてのBreimanおよびCutlerの集合体から予測する 
"GaussianProcess" ガウス過程の事前分布を関数に使って予測する - 次は,PerformanceGoalの可能な設定値である.
-
"DirectTraining" モデルを検索することなしに,直接データ集合全体について訓練する "Memory" 予測器の保存条件を最小にする "Quality" 予測器の確度を最大にする "Speed" 予測器の速度を最大にする "TrainingSpeed" 予測器の作成にかける時間を最小にする Automatic スピード,確度,メモリの自動トレードオフ {goal1,goal2,…} goal1,goal2等を自動的に組み合せる - TrainingProgressReportingの設定として以下を使うことができる.
-
"Panel" 動的に更新されるグラフィカルなパネルを表示する "Print" Printを使って定期的に情報をレポートする "ProgressIndicator" 簡単なProgressIndicatorを表示する "SimplePanel" 学習曲線なしでパネルを動的に更新する None 情報は何もレポートしない - 入手したPredictorFunction[…]にInformationを使うことができる.
例題
すべて開く すべて閉じる例 (2)
行列の第1列と第2列の特徴を使った第3列の予測方法を学習する:
p = Predict[(| | | |
| ---- | --- | ---- |
| 1.3 | "P" | 1 |
| 1.8 | "Q" | 2.5 |
| 1.9 | "Q" | 3 |
| 0.2 | "P" | 1 |
| -3.2 | "P" | -4.2 |
| 0.3 | "Q" | 2 |) -> 3]p[{1.8, "Q"}]p[{1.8, Missing[]}]p[{{1.8, "Q"}, {.4, "P"}}]data = {1 -> 1.3, 2 -> 2.4, 3 -> 4.4, 4 -> 5.1, 6 -> 7.3};p = Predict[data, Method -> "LinearRegression"]例の特徴が与えられた場合に,予測された値の条件付き分布を得る:
𝒟 = p[1.5, "Distribution"]Plot[PDF[𝒟, x], {x, 0, 4}]Show[
ListPlot[List@@@data, PlotStyle -> {Red, PointSize@Large}],
ListLinePlot[Table[{x, Around@@p[x, "Distribution"]}, {x, 0, 10}], IntervalMarkers -> "Bands"]
]スコープ (24)
データ形式 (7)
Predict[{1 -> -1.14, 2 -> -0.34, 3 -> 0.46, 4 -> 1.26, 5 -> 2.06}]Predict[{{-0.78, 0.58} -> 0.86, {-0.62, -0.52} -> 2.28, {-0.87, 0.08} -> 1.18, {-0.54, -0.21} -> 2.13, {0.4, -0.58} -> 4.38}]Predict[{<|"f1" -> -0.78, "f2" -> 0.58|> -> 0.86, <|"f1" -> -0.62, "f2" -> -0.52|> -> 2.28, <|"f1" -> -0.87, "f2" -> 0.08|> -> 1.18, <|"f1" -> -0.54, "f2" -> -0.21|> -> 2.13, <|"f1" -> 0.4, "f2" -> -0.58|> -> 4.38}]訓練集合を入力リストと出力リストの間の規則のリストとして指定する:
Predict[{1, 2, 3, 4, 5} -> {-1.14, -0.34, 0.46, 1.26, 2.06}]Predict[{{1, -1.14}, {2, -0.34}, {3, 0.46}, {4, 1.26}, {5, 2.06}} -> 2]Predict[{<|"f1" -> 1, "f2" -> -1.14|>, <|"f1" -> 2, "f2" -> -0.34|>, <|"f1" -> 3, "f2" -> 0.46|>, <|"f1" -> 4, "f2" -> 1.26|>, <|"f1" -> 5, "f2" -> 2.06|>} -> "f2"]Predict[Dataset[{Association["f1" -> 1, "f2" -> -1.1400000000000001],
Association["f1" -> 2, "f2" -> -0.34], Association["f1" -> 3, "f2" -> 0.46],
Association["f1" -> 4, "f2" -> 1.26], Association["f1" -> 5, "f2" -> 2.06]}] -> "f2"]データ型 (13)
数値 (3)
Predict[{0.72 -> -1.56, 0.36 -> -2.28, -0.18 -> -3.36, -0.4 -> -3.8, 0.06 -> -2.88}]Predict[{{0.19, 0.44} -> 2.94, {0.82, -0.99} -> 5.63, {-0.82, 0.83} -> 0.53, {-0.25, -0.27} -> 2.77, {-0.9, 0.81} -> 0.39}]Predict[{{{0.08, 0.73}, {0.33, -0.45}} -> -0.37, {{0.28, 0.4}, {-0.34, -0.92}} -> -0.64, {{-0.82, 0.35}, {-0.17, 0.93}} -> 0.11, {{0.46, -0.33}, {0.67, 0.82}} -> 1.28, {{0.39, -0.6}, {0.7, 0.34}} -> 0.73}]名義 (3)
Predict[{"B" -> 0.61, "A" -> -0.93, "B" -> 0.26, "B" -> 0.65, "B" -> 0.47}]p = Predict[<|"Treatment" -> {"A", "B", "A", "C", "B", "C", "A", "B", "C", "A"}, "Severity" -> {"High", "Medium", "Low", "High", "Low", "Medium", "Medium", "High", "Low", "High"}, "Recovery Time" -> {8, 6, 4, 9, 5, 7, 6, 8, 5, 8}|> -> "Recovery Time"]p[<|"Treatment" -> "C", "Severity" -> "High"|>]p = Predict[Dataset[{Association["Treatment" -> "A", "Severity" -> "High", "Patient's History" -> "Yes",
"Age" -> 55], Association["Treatment" -> "B", "Severity" -> "Medium",
"Patient's History" -> "No", "Age" -> 45], Association["Treatment" -> "A", "Severity" -> "Low",
"Patient's History" -> "Yes", "Age" -> 30], Association["Treatment" -> "C",
"Severity" -> "High", "Patient's History" -> "No", "Age" -> 60],
Association["Treatment" -> "B", "Severity" -> "Low", "Patient's History" -> "Yes", "Age" -> 35],
Association["Treatment" -> "C", "Severity" -> "Medium", "Patient's History" -> "No",
"Age" -> 50]}] -> Dataset[{Association["Recovery Time" -> 8], Association["Recovery Time" -> 6],
Association["Recovery Time" -> 4], Association["Recovery Time" -> 9],
Association["Recovery Time" -> 5], Association["Recovery Time" -> 7]}]]p[<|"Treatment" -> "C", "Age" -> 42, "Patient's History" -> "No"|>]数量 (1)
Quantityオブジェクトを含むデータで予測器を訓練する:
p = Predict[Dataset[{Association["Neighborhood" -> "Sunnypoint", "Area" -> Quantity[1500, "Feet"^2],
"Price" -> Quantity[300000, "USDollars"]], Association["Neighborhood" -> "Moonbrook",
"Area" -> Quantity[1800, "Feet"^2], "Price" -> Quantity[360000, "USDollars"]],
Association["Neighborhood" -> "Sunnypoint", "Area" -> Quantity[1700, "Feet"^2],
"Price" -> Quantity[340000, "USDollars"]], Association["Neighborhood" -> "Starville",
"Area" -> Quantity[2000, "Feet"^2], "Price" -> Quantity[500000, "USDollars"]],
Association["Neighborhood" -> "Moonbrook", "Area" -> Quantity[1600, "Feet"^2],
"Price" -> Quantity[320000, "USDollars"]], Association["Neighborhood" -> "Starville",
"Area" -> Quantity[2200, "Feet"^2], "Price" -> Quantity[550000, "USDollars"]],
Association["Neighborhood" -> "Sunnypoint", "Area" -> Quantity[1400, "Feet"^2],
"Price" -> Quantity[280000, "USDollars"]], Association["Neighborhood" -> "Moonbrook",
"Area" -> Quantity[1900, "Feet"^2], "Price" -> Quantity[380000, "USDollars"]],
Association["Neighborhood" -> "Starville", "Area" -> Quantity[2100, "Feet"^2],
"Price" -> Quantity[520000, "USDollars"]], Association["Neighborhood" -> "Sunnypoint",
"Area" -> Quantity[1800, "Feet"^2], "Price" -> Quantity[360000, "USDollars"]]}] -> "Price"]p[<|"Neighborhood" -> "Moonbrook", "Area" -> Quantity[900, "Feet"^2]|>]既知であるのが"Neighborhood"のみの場合に最もありそうな価格を予測する:
p[<|"Neighborhood" -> "Moonbrook"|>]テスト (1)
色 (1)
Predict[{RGBColor[0.374533954339318, 0.07318946913456625, 0.34948076712998266], RGBColor[0.7085138807325013, 0.5508514126801727, 0.270668676806443], RGBColor[0.482424250096966, 0.9866683639813978, 0.8763664701273515], RGBColor[0.9143901752719417, 0.5933340939498908, 0.12490074751913904], RGBColor[0.5435848746538026, 0.3320246736743131, 0.10546267186910474], RGBColor[0.4838618865454345, 0.1408408308353548, 0.4182003855819225], RGBColor[0.09486596097451105, 0.4061453278622089, 0.19070989282627604], RGBColor[0.9978640282936782, 0.9850053326406092, 0.6079629315168287], RGBColor[0.7423358808871543, 0.14441876671667964, 0.44156741749306994], RGBColor[0.11647231911978806, 0.14156287966553882, 0.7585884183769138], RGBColor[0.413441306192059, 0.35488417001075656, 0.4547933589911124], RGBColor[0.6479088100736257, 0.06575533518383936, 0.33956768046537045], RGBColor[0.43617515288692754, 0.395321922119783, 0.03284974966398546], RGBColor[0.08988572988782773, 0.45387554090065807, 0.565445988533821], RGBColor[0.5962404964416488, 0.7115775209469246, 0.5937470103610984], RGBColor[0.5425615924830165, 0.9052557429558079, 0.7950524706591187], RGBColor[0.258709017611374, 0.05898221147135585, 0.04550888101080042], RGBColor[0.733150150511475, 0.5972827779202361, 0.34440914488265517], RGBColor[0.9604086664357256, 0.9762505577301217, 0.6004232657263842], RGBColor[0.10316670441111997, 0.3667737206326349, 0.46355431351130827]} -> {0.22, 0.61, 0.91, 0.7, 0.42, 0.31, 0.38, 0.97, 0.44, 0.26, 0.41, 0.37, 0.43, 0.45, 0.71, 0.85, 0.13, 0.65, 0.96, 0.37}, {Red, Green, Blue}]画像 (1)
Predict[{[image] -> 40.2, [image] -> 8.9, [image] -> 11., [image] -> 4.9, [image] -> 13.6, [image] -> 15.6, [image] -> 14.7, [image] -> 3.8, [image] -> 34.7, [image] -> 10.8, [image] -> 4., [image] -> 16.1, [image] -> 3.3, [image] -> 8.3, [image] -> 12.6}]列 (1)
欠けたデータ (2)
Predict[{{2.3, "male"} -> 1, {4.8, Missing[]} -> 2.5, {Missing[], "female"} -> 8.4, {5.2, "female"} -> -2, {Missing[], "male"} -> -4.2, {1.3, "male"} -> 10}]名前付きの特徴を持つデータ集合で予測器を訓練する.キーの順序は重要ではない.キーはなくてもよい:
p = Predict[{
<|"age" -> 24, "sex" -> "female"|> -> 10.4,
<|"sex" -> "male", "age" -> 13|> -> 5.2,
<|"age" -> 57|> -> 23.3,
<|"sex" -> "male"|> -> 14.3}]p[{<|"age" -> 31|>, <|"sex" -> "male"|>, <||>}]情報 (4)
Information[PredictorFunction[Association["ExampleNumber" -> 6,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"],
"f2" -> Assoc ... "Date" -> DateObject[{2023, 7, 26, 16, 30, 52.286118`8.470961373666972}, "Instant",
"Gregorian", 2.], "ProcessorCount" -> 10, "ProcessorType" -> "ARM64",
"OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, "Evaluations" -> {}]]]]Information[PredictorFunction[Association["ExampleNumber" -> 6,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"],
"f2" -> Assoc ... "Date" -> DateObject[{2023, 7, 26, 16, 30, 52.286118`8.470961373666972}, "Instant",
"Gregorian", 2.], "ProcessorCount" -> 10, "ProcessorType" -> "ARM64",
"OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, "Evaluations" -> {}]]], #]& /@ {"FeatureNames", "FeatureNumber", "FeatureTypes"}Information[PredictorFunction[Association["ExampleNumber" -> 6,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"],
"f2" -> Assoc ... "Date" -> DateObject[{2023, 7, 26, 16, 30, 52.286118`8.470961373666972}, "Instant",
"Gregorian", 2.], "ProcessorCount" -> 10, "ProcessorType" -> "ARM64",
"OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, "Evaluations" -> {}]]], "FeatureExtractor"]Information[PredictorFunction[Association["ExampleNumber" -> 6,
"Input" -> Association["Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset",
Association["Input" -> Association["f1" -> Association["Type" -> "Numerical"],
"f2" -> Assoc ... "Date" -> DateObject[{2023, 7, 26, 16, 30, 52.286118`8.470961373666972}, "Instant",
"Gregorian", 2.], "ProcessorCount" -> 10, "ProcessorType" -> "ARM64",
"OperatingSystem" -> "MacOSX", "SystemWordLength" -> 64, "Evaluations" -> {}]]], "Properties"]オプション (23)
AcceptanceThreshold (1)
p = Predict[{1 -> 1.2, 2 -> 3.5, 3.5 -> 5.4, 4 -> 2.3}, AnomalyDetector -> Automatic]p[6, AcceptanceThreshold -> 0.01]p[6, AcceptanceThreshold -> 0.0001]p2 = Predict[p, AcceptanceThreshold -> 0.01]p2[6]AnomalyDetector (1)
p = Predict[{1 -> 1.2, 2 -> 3.5, 3.5 -> 5.4, 4 -> 2.3}, AnomalyDetector -> Automatic]p[1.2]p[100000.2]"Distribution"特性は異常検出器の影響を受けない:
p[100000.2, "Distribution"]p[10000.2, AnomalyDetector -> None]p2 = Predict[p, AnomalyDetector -> None]p2[10000.2]FeatureExtractor (2)
FeatureExtractorを使ってカスタム関数でデータを前処理する予測関数を生成する:
data = {DateObject[{2014, 5, 5}, TimeObject[{9, 53, 6.30158}, TimeZone -> -5.], TimeZone -> -5.] -> 1, DateObject[{2000, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -5.], TimeZone -> -5.] -> 2, DateObject[{2007, 8, 23}] -> 3, DateObject[{2016, 4, 4}, TimeObject[{15, 59, 18.2738}, TimeZone -> -4.], TimeZone -> -4.] -> 4};p = Predict[data, FeatureExtractor -> ({AbsoluteTime[#], #["Year"]}&)]"StandardizedVector"メソッドを前処理ルートに加える:
p = Predict[data, FeatureExtractor -> {{AbsoluteTime[#], #["Year"]}&, "StandardizedVector"}]p[DateObject[{2017, 1, 18}, TimeObject[{23, 24, 10.099}, TimeZone -> -5.], TimeZone -> -5.]]{features, fe} = FeatureExtraction[{DateObject[{2014, 5, 5, 9, 53, 6.30158}, "Instant", "Gregorian", -5.], DateObject[{2000, 1, 1, 0, 0, 0.}, "Instant", "Gregorian", -5.], DateObject[{2007, 8, 23}, "Day", "Gregorian", -5.], DateObject[{2016, 4, 4, 15, 59, 18.2738}, "Instant", "Gregorian", -4.]}, {{AbsoluteTime[#], #["Year"]}&, "StandardizedVector"}, {"ExtractedFeatures", "ExtractorFunction"}]p = Predict[features -> {1, 2, 3, 4}]p2 = Predict[p, FeatureExtractor -> fe]p2[DateObject[{2017, 1, 18}, TimeObject[{23, 24, 10.099}, TimeZone -> -5.], TimeZone -> -5.]]FeatureNames (2)
p = Predict[{{2.3, "male"} -> 1, {4.8, Missing[]} -> 2.5, {Missing[], "female"} -> 8.4, {5.2, "female"} -> -2, {Missing[], "male"} -> -4.2, {1.3, "male"} -> 10}, FeatureNames -> {"age", "gender"}]p[<|"age" -> 3.3, "gender" -> "male"|>]p[{3.3, "male"}]名前付きの特徴がある訓練集合で予測器を訓練し,FeatureNamesを使ってその順序を設定する:
p = Predict[{<|"age" -> 2.3, "gender" -> "male"|> -> 1, <|"age" -> 4.6|> -> 2.5, <|"gender" -> "female"|> -> 8.4, <|"gender" -> "female", "age" -> 5.2|> -> -2}, FeatureNames -> {"gender", "age"}]Information[p, FeatureNames]p[{"female", 6.5}]FeatureTypes (2)
trainingset = {{"example", "a"} -> 1.4, {"example", "a"} -> 2.7, {"an example again", "b"} -> 2.7};p = Predict[trainingset]Information[p, FeatureTypes]p = Predict[trainingset, FeatureTypes -> {"Text", "Nominal"}]Information[p, FeatureTypes]p[{"a new example", "b"}]trainingset = {
<|"age" -> 32, "gender" -> 1|> -> 4.3,
<|"age" -> 41, "gender" -> 2|> -> 1.2,
<|"age" -> 17, "gender" -> 2|> -> 1.4,
<|"age" -> 11, "gender" -> 1|> -> 5.1};p = Predict[trainingset]Information[p, FeatureTypes]"gender"という特徴は名義的であるとみなすように指定する:
p = Predict[trainingset, FeatureTypes -> <|"gender" -> "Nominal"|>]Information[p, FeatureTypes]IndeterminateThreshold (1)
p = Predict[{1 -> 1.2, 2 -> 1.4, 3 -> 4.5, 4 -> 6.8}, IndeterminateThreshold -> 0.5]example = 3.4;
pdf = PDF[p[example, "Distribution"]]Plot[pdf[x], {x, 2, 8}, PlotRange -> All]p[example]p[example, IndeterminateThreshold -> 0.]p2 = Predict[p, IndeterminateThreshold -> 0.]p2[example]Method (4)
trainingset = {1, 2, 3, 4, 5, 6} -> {2, 3, 5, 8, 9, 7};linear = Predict[trainingset, Method -> "LinearRegression"]nn = Predict[trainingset, Method -> "NearestNeighbors"]両方の予測器について,予測された値を特徴の関数としてプロットする:
Plot[{linear[x], nn[x]}, {x, 0, 7}, Exclusions -> None]trainingset = ExampleData[{"MachineLearning", "BostonHomes"}, "TrainingData"];p1 = Predict[trainingset, Method -> "RandomForest"]testset = ExampleData[{"MachineLearning", "BostonHomes"}, "TestData"];PredictorMeasurements[p1, testset, "StandardDeviation"]この例では,線形回帰予測器を使うと剰余の標準偏差が大きくなる:
p2 = Predict[trainingset, Method -> "LinearRegression"]PredictorMeasurements[p2, testset, "StandardDeviation"]Information[#, "TrainingTime"] & /@ {p1, p2}線形回帰予測器,神経回路網予測器,ガウス過程予測器を訓練する:
data = {1, 2, 3, 4, 5, 6, 7, 8, 9} -> {1, 2, 3, 4, 5, 6, 7, 8, 9} ^ 4;{neural, linear, gaussprocess} = Predict[data, Method -> #]& /@ {"NeuralNetwork", "LinearRegression", "GaussianProcess"}Show[ListPlot@data[[2]], Plot[{neural[x], linear[x], gaussprocess[x]}, {x, 0, 10}, Exclusions -> None]]{nearest, forest} = Predict[data, Method -> #]& /@ {"NearestNeighbors", "RandomForest"}Show[ListPlot@data[[2]], Plot[{forest[x], nearest[x]}, {x, 0, 10}, Exclusions -> None]]神経回路網予測器,ランダムフォレスト予測器,ガウス過程予測器を訓練する:
data = Table[n -> Sin[n], {n, 1, 10}];{neuralnetwork, randomforest, gaussianprocess} = Predict[data, Method -> #]& /@ {"NeuralNetwork", "RandomForest", "GaussianProcess"}Show[Plot[{neuralnetwork[x], randomforest[x], gaussianprocess[x]}, {x, 1, 10}, PlotLegends -> {"NeuralNetwork", "RandomForest", "GaussianProcess"}, Frame -> True, Exclusions -> None], ListPlot[List@@@data, PlotStyle -> Directive[PointSize[Medium], Red]]]MissingValueSynthesis (1)
x = {{1, 3}, {2, 4}, {3, 5}, {4, 4}, {5, 8}, {6, 9}, {7, 4}, {8, 6}, {9, 12}};
y = {2, 4, 5, 4, 6, 7, 4, 5, 9};
p = Predict[x -> y]p[{5, Missing[]}]欠測値の合成を設定して,既知の値が与えられた場合に各欠測変数を推定される最も可能性の高い値に置き換える(これはデフォルト動作である):
p[{5, Missing[]}, MissingValueSynthesis -> "ModeFinding"]欠落している変数を既知の値を条件としてランダムサンプルで置き換える:
p[{5, Missing[]}, MissingValueSynthesis -> "RandomSampling"]多くのランダムな代入を平均化することが通常は最良の戦略であり,代入によって引き起こされる不確実性を取得することができる:
MeanAround[Table[p[{5, Missing[]}, MissingValueSynthesis -> "RandomSampling"], 100]]訓練中に学習メソッドを指定して,データの分布についての学習方法を制御する:
p = Predict[x -> y, MissingValueSynthesis -> "KernelDensityEstimation"]"KernelDensityEstimation"分布を使って値に条件を付けることで欠落値のある例を予測する:
p[{5, Missing[]}]訓練で既存のLearnedDistributionを提供し,訓練中の欠落値の代入と後の評価でこれを使う:
dist = LearnDistribution[x, Method -> "Multinormal"];
p = Predict[x -> y, MissingValueSynthesis -> dist];
p[{5, Missing[]}]個々の評価のために欠落値を合成するために既存のLearnedDistributionを指定する:
dist2 = LearnDistribution[x, Method -> "KernelDensityEstimation"];
p[{5, Missing[]}, MissingValueSynthesis -> dist2]訓練時に連想を渡すことで学習方法と評価戦略の両方を制御する:
p = Predict[x -> y, MissingValueSynthesis ->
<|"LearningMethod" -> "Multinormal", "EvaluationStrategy" -> "RandomSampling"|>];
p[{5, Missing[]}]PerformanceGoal (1)
trainingset = ExampleData[{"MachineLearning", "WineQuality"}, "TrainingData"];p1 = Predict[trainingset, PerformanceGoal -> "TrainingSpeed"]Information[p1, "TrainingTime"]testset = ExampleData[{"MachineLearning", "WineQuality"}, "TestData"];PredictorMeasurements[p1, testset, "StandardDeviation"]デフォルトで,予測速度とパフォーマンスの間で妥協が求められる:
p2 = Predict[trainingset]Information[p2, "TrainingTime"]PredictorMeasurements[p2, testset, "StandardDeviation"]同じデータを使い,訓練速度とメモリに重点を置いて予測器を訓練する:
p3 = Predict[trainingset, PerformanceGoal -> {"TrainingSpeed", "Memory"}]ByteCount /@ {p2, p3}PredictorMeasurements[p3, testset, "StandardDeviation"]RecalibrationFunction (1)
training = RandomSample[ResourceData["Sample Data: Boston Homes", "TrainingData"]];
test = ResourceData["Sample Data: Boston Homes", "TestData"];p = Predict[training, Method -> "RandomForest", RecalibrationFunction -> All]PredictorMeasurements[p, test, "ComparisonPlot"]p2 = Predict[p, RecalibrationFunction -> None]PredictorMeasurements[p2, test, "ComparisonPlot"]TargetDevice (1)
ニューラルネットワークを使ってシステムのデフォルトGPUで予測器を訓練し,AbsoluteTimingを見る:
n = 10000;
trainingData = RandomReal[1, {n, 4}] -> RandomReal[1, n];
AbsoluteTiming[predictor = Predict[trainingData, Method -> "NeuralNetwork", TargetDevice -> "GPU"]]この結果を,デフォルトのCPU計算で得られた時間と比較する:
AbsoluteTiming[predictor = Predict[trainingData, Method -> "NeuralNetwork"]]TimeGoal (2)
p = Predict[{1, 2, 3, 4} -> {1, 2, 3, 4}, TimeGoal -> Quantity[3, "Seconds"]]Information[p, "TrainingTime"]dataset = ExampleData[{"MachineLearning", "BostonHomes"}, "Data"];
testset = ExampleData[{"MachineLearning", "BostonHomes"}, "TestData"];p = Predict[dataset, TimeGoal -> .1]PredictorMeasurements[p, testset, "StandardDeviation"]p = Predict[dataset, TimeGoal -> 5]PredictorMeasurements[p, testset, "StandardDeviation"]TrainingProgressReporting (1)
dataset = ExampleData[{"MachineLearning", "WineQuality"}, "Data"];予測器の訓練中に,訓練の進捗状況をインタラクティブに表示する:
Predict[dataset, TrainingProgressReporting -> "Panel"];Predict[dataset, TrainingProgressReporting -> "SimplePanel"];Predict[dataset, TrainingProgressReporting -> "Print"];Predict[dataset, TrainingProgressReporting -> "ProgressIndicator"];Predict[dataset, TrainingProgressReporting -> None];UtilityFunction (2)
trainingset = {1 -> 1.1, 2 -> 4.4, 3 -> 6.1, 4 -> 7.1, 5 -> 9.2};p1 = Predict[trainingset]example = 2.4;
pdf = PDF[p1[example, "Distribution"]]Plot[pdf[x], {x, 1, 7}, PlotRange -> All]p1[example]Information[p1, UtilityFunction]予測された値が実際の値よりも小さかった場合にペナルティを科す効用関数を定義する:
utility[a_, p_] := -Piecewise[{{Exp[p - a], a < p}, {Exp[3 * (a - p)], a ≥ p}}]Plot[utility[0, p], {p, -1, 2}]p2 = Predict[trainingset, UtilityFunction -> utility]p2[example]Plot[PDF[p2[example, "Distribution"]][x], {x, 1, 7}, PlotRange -> All]予測の際に効用関数を指定すると,訓練の際に指定された効用関数が取って代られる:
p2[example, UtilityFunction -> (DiracDelta[#2 - #1]&)]p3 = Predict[p2, UtilityFunction -> (DiracDelta[#2 - #1]&)]p3[example]組込みの予測器"NameAge"を使って"Claire"という名前の年齢分布を可視化する:
distribution = Predict["NameAge", "Claire", "Distribution"]Plot[PDF[distribution, x], {x, 0, 100}, Exclusions -> None, PlotRange -> All]Predict["NameAge", "Claire"]効用関数を変え,最も可能性の高い値の代りに平均値を予測する:
Predict["NameAge", "Claire", UtilityFunction -> Function[-(#2 - #1) ^ 2], IndeterminateThreshold -> 0]ValidationSet (1)
"WineQuality"データについて線形回帰予測器を訓練する:
trainingset = ExampleData[{"MachineLearning", "WineQuality"}, "TrainingData"];p1 = Predict[trainingset, Method -> "LinearRegression"]Information[p1, "L2Regularization"]validationset = ExampleData[{"MachineLearning", "WineQuality"}, "TestData"];p2 = Predict[trainingset, ValidationSet -> validationset, Method -> "LinearRegression"]Information[p2, "L2Regularization"]アプリケーション (6)
基本的な線形回帰 (1)
地域のいくつかの特徴を与え,ボストン近郊における不動産物件の中央値を予測する予測器を訓練する:
p = Predict[ExampleData[{"MachineLearning", "BostonHomes"}, "TrainingData"], PerformanceGoal -> "Quality"]PredictorMeasurementsObjectを生成し,検定集合についての予測器のパフォーマンスを分析する:
pm = PredictorMeasurements[p, ExampleData[{"MachineLearning", "BostonHomes"}, "TestData"]]予測された値の関数としての検定集合の値の散布図を可視化する:
pm["ComparisonPlot"]pm["StandardDeviation"]気象分析 (1)
月ごとの平均気温のデータ集合を,町,年,月の関数としてロードする:
dataset = RandomSample[{#2, ToExpression[#3], #4} -> (#1 - 32) / 1.8& @@@ExampleData[{"Statistics", "USCityTemperature"}]];RandomSample[dataset, 5] // TableFormp = Predict[dataset, Method -> "LinearRegression"]2020年のいくつかの月について予測された,都市"Lincoln"の気温分布をプロットする:
Plot[{
PDF[p[{"Lincoln", 2020, "January"}, "Distribution"], x],
PDF[p[{"Lincoln", 2020, "May"}, "Distribution"], x], PDF[p[{"Lincoln", 2020, "August"}, "Distribution"], x]
}, {x, -10, 30}, PlotLegends -> {"January", "May", "August"}]各月について,予測された気温とエラーバー(標準偏差)をプロットする:
months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};distributions = MapIndexed[
{First[#2], p[{"Lincoln", 2020, #1}, "Distribution"]}&, months];ListPlot[
{#1, Around[#2[[1]], #2[[2]]]}&@@@distributions, IconizedObject[«options»]]品質評価 (1)
ワインの品質についてのデータ集合をワインの物質特性の関数としてロードする:
trainingset = ExampleData[{"MachineLearning", "WineQuality"}, "TrainingData"];RandomSample[trainingset, 3] // TableFormExampleData[{"MachineLearning", "WineQuality"}, "VariableDescriptions"]{Histogram[trainingset[[All, 1, 11]], PlotLabel -> "alcohol"], Histogram[trainingset[[All, 1, 9]], PlotLabel -> "pH"]}p = Predict[trainingset]unknownwine = {7.6, 0.48, 0.31, 9.4, 0.046, 6., 194., 0.99714, 3.07, 0.61, 9.4};p[unknownwine]未知のワインの品質を予測する関数をそのpHとアルコールレベルの関数として作成する:
quality[pH_, alcohol_] := p[{7.6, 0.48, 0.31, 9.4, 0.046, 6., 194., 0.99714, pH, 0.61, alcohol}];関数をプロットしてこのワインを向上させるためのヒントを得る:
Show[Plot3D[quality[pH, alcohol], {pH, 2.8, 3.8} , {alcohol, 8, 14}, AxesLabel -> Automatic, Exclusions -> None], ListPointPlot3D[{{3.07, 9.4, p[unknownwine]}}, PlotStyle -> {Red, PointSize[.05]}]]解釈可能な機械学習 (1)
ワインの品質についてのデータ集合をワインの物質特性の関数としてロードする:
wine = ResourceData["Sample Data: Wine Quality"];p = Predict[wine -> "WineQuality"]
x = KeyDrop[wine, "WineQuality"];bottle = Last[x]predictedquality = p[bottle]この瓶の予測された品質が平均よりもどの程度高い/低いかを計算する:
meanquality = Information[p, "TrainingLabelMean"];
predictedquality - meanqualityこの瓶についての予測器の出力に各特徴がどの程度影響したかを推定する:
impacts = p[bottle, "SHAPValues"]BarChart[Sort[impacts], ChartLabels -> Placed[Automatic, After], ImageSize -> Medium, BarOrigin -> Left, PlotLabel -> "Impact of Feature on Prediction"]シャープレイの値が予測された品質を完全に説明していることを確認する:
Total[impacts]
meanquality + Total[impacts] == predictedqualitydist = LearnDistribution[x, Method -> {"Multinormal", "CovarianceType" -> "Diagonal"}]SHAP値の特徴の重要性を100本のワインについて推定する.各推定には5つのサンプルを使う:
winebottles = RandomSample[x, 100];
shaps = p[winebottles, "SHAPValues" -> 5, MissingValueSynthesis -> dist];importance = Mean[Abs[shaps]]BarChart[Sort[importance], ChartLabels -> Placed[Automatic, After], ImageSize -> Medium, BarOrigin -> Left, PlotLabel -> "Average Feature Impact"]特徴の値とモデル予測に対するその影響の間の非線形の関係を可視化する:
ListPlot[Thread[{Normal[winebottles][[All, "TotalSulfurDioxide"]], shaps[[All, "TotalSulfurDioxide"]]}], AxesLabel -> {"Feature Value", "Feature Impact"}, PlotMarkers -> Automatic]コンピュータビジョン (1)
trainingset = Image[AngularGauge[#]] -> #& /@ RandomReal[1, 300];Export["AngularGauge_example.mx", trainingset]RandomSample[trainingset, 3]predictor = Predict[trainingset]predictor[[image]]Dynamicを使って予測器とインタラクトする:
Row[{AngularGauge[Dynamic[t]], Style["->", Large], Dynamic[Labeled[AngularGauge[predictor[Image[AngularGauge[t]]]], "(predicted value)"]]}, BaseStyle -> FontFamily -> "Sans Serif"]顧客の行動分析 (1)
顧客の購買行動についてのデータを含むデータ集合をインポートする:
dataset = IconizedObject[«customer data»];RandomChoice[dataset]"GradientBoostedTrees"モデルを訓練して他の特徴から総支出額を予測するようにする:
model = Predict[dataset -> "Total_Spent", Method -> "GradientBoostedTrees"]このモデルを使って地域別の最も可能性が高い支出額を予測する:
spendingByLocation = AssociationMap[model[<|"Location" -> #|>]&, dataset[Union, "Location"]]GeoBubbleChart[spendingByLocation]支出額が多い上位3都市について,支出額を顧客年齢の関数として推定する:
topCities = Take[spendingByLocation, 3]//Keys//Normalyears = Range@@dataset[MinMax, "Age"]//Normal;predictions = Table[
model[Table[<|"Age" -> y, "Location" -> city|>, {y, years}], "Distribution"],
{city, topCities}
] /. {QuantityDistribution -> Quantity, NormalDistribution -> Around};points = Table[Thread[{years, res}], {res, predictions}];ListLinePlot[points, Frame -> True, FrameLabel -> Automatic, IntervalMarkers -> "Bands", ImageSize -> Medium, PlotLegends -> topCities]特性と関係 (1)
正規化しない線形回帰予測器とLinearModelFitは,同等のモデルを訓練することができる:
data = Table[{i, RandomReal[{i - 1, i}]}, {i, 10}]p = Predict[Rule@@@data, Method -> {"LinearRegression", "L2Regularization" -> 0}]Information[p, "Function"]LinearModelFit[data, x, x]FitとNonlinearModelFitは同等のこともある:
Fit[data, {1, x}, x]NonlinearModelFit[data, a + b x, {a, b}, x]考えられる問題 (1)
RandomSeedingオプションは,常に結果の再生可能性を保証する訳ではない.
"WineQuality"データ集合についていくつかの予測器を訓練する:
dataset = ExampleData[{"MachineLearning", "WineQuality"}, "Data"];predictors = Table[Predict[dataset], 3];testset = ExampleData[{"MachineLearning", "WineQuality"}, "TestData"];SameQ@@(#[testset[[All, 1]]]& /@ predictors)おもしろい例題 (1)
1Dデータから学習した後で指定されたメソッドの予測を可視化する関数を作る:
visualizePrediction[data_, method_] := Module[
{p, predictionplot, dataplot, xs},
dataplot = ListPlot[List@@@data, PlotStyle -> Red, PlotLegends -> {"Data"}];
xs = data[[All, 1]];
p = Predict[data, Method -> method];
predictionplot = Plot[{
p[x],
p[x] + StandardDeviation[p[x, "Distribution"]], p[x] - StandardDeviation[p[x, "Distribution"]]
}, {x, Min[xs] - 1, Max[xs] + 1}, PlotStyle -> {Blue, Gray, Gray}, Filling -> {2 -> {3}}, Exclusions -> False, PerformanceGoal -> "Speed", PlotLegends -> {"Prediction", "Confidence Interval"}];
Show[predictionplot, dataplot, PlotLabel -> method, ImageSize -> 250]
];単純なデータ集合についてこの関数を"GaussianProcess"メソッドで試してみる:
visualizePrediction[{-1.2 -> 1.2, 1.4 -> 1.4, 3.1 -> 1.8, 4.5 -> 1.6}, "GaussianProcess"]Grid[Partition[visualizePrediction[{-1.2 -> 1.2, 1.4 -> 1.4, 3.1 -> 1.8, 4.5 -> 1.6}, #][[1, 1]]& /@ {"LinearRegression", "NearestNeighbors", "RandomForest", "NeuralNetwork"}, 2], Frame -> All, FrameStyle -> LightGray]関連するガイド
-
▪
- 機械学習 ▪
- コンピュータビジョン ▪
- 教師あり機械学習 ▪
- 表形式モデリング ▪
- 音声解析 ▪
- 科学的データ解析 ▪
- 表形式処理の概要 ▪
- 生命科学と医学のデータと計算 ▪
- 機械学習法
履歴
2014 で導入 (10.0) | 2016 で更新 (10.4) ▪ 2017 (11.2) ▪ 2018 (11.3) ▪ 2019 (12.0) ▪ 2020 (12.1) ▪ 2021 (12.3) ▪ 2025 (14.2)
テキスト
Wolfram Research (2014), Predict, Wolfram言語関数, https://reference.wolfram.com/language/ref/Predict.html (2025年に更新).
CMS
Wolfram Language. 2014. "Predict." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/Predict.html.
APA
Wolfram Language. (2014). Predict. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Predict.html
BibTeX
@misc{reference.wolfram_2026_predict, author="Wolfram Research", title="{Predict}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Predict.html}", note=[Accessed: 28-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_predict, organization={Wolfram Research}, title={Predict}, year={2025}, url={https://reference.wolfram.com/language/ref/Predict.html}, note=[Accessed: 28-November-2026]}