2024-09-04 陈若兮 风俗小资讯
python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.cluster import KMeans
Load the data
data = pd.read_csv('8_char_data.csv')
Preprocess the data
data = data.dropna()
data = data.apply(pd.to_numeric)
Scale the data
scaler = StandardScaler()
data = scaler.fit_transform(data)
Perform PCA
pca = PCA(n_components=2)
pca_data = pca.fit_transform(data)
Plot the data
plt.scatter(pca_data[:, 0], pca_data[:, 1])
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.title('PCA of 8 char data')
plt.show()
Perform KMeans clustering
kmeans = KMeans(n_clusters=4)
kmeans.fit(pca_data)
Plot the clusters
plt.scatter(pca_data[:, 0], pca_data[:, 1], c=kmeans.labels_)
plt.xlabel('PC1')
plt.ylabel('PC2')
plt.title('KMeans clustering of 8 char data')
plt.show()
```php
// 八字算命
class Bazi {
// 八字数据
private $data;
// 初始化
public function __construct($data) {
$this>data = $data;
}
// 获取八字五行
public function getWuxing() {
$wuxing = array();
foreach ($this>data as $key => $value) {
$wuxing[$key] = $this>getWuxingByGan($value);
}
return $wuxing;
}
// 根据干支获取五行
private function getWuxingByGan($gan) {
switch ($gan) {
case '甲':
case '乙':
return '木';
case '丙':
case '丁':
return '火';
case '戊':
case '己':
return '土';
case '庚':
case '辛':
return '金';
case '壬':
case '癸':
return '水';
default:
return '未知';
}
}
// 获取八字生旺死绝
public function getShengWangSiJue() {
$shengwangsijue = array();
foreach ($this>data as $key => $value) {
$shengwangsijue[$key] = $this>getShengWangSiJueByGan($value);
}
return $shengwangsijue;
}
// 根据干支获取生旺死绝
private function getShengWangSiJueByGan($gan) {
switch ($gan) {
case '甲':
case '乙':
return '木旺';
case '丙':
case '丁':
return '火旺';
case '戊':
case '己':
return '土旺';
case '庚':
case '辛':
return '金旺';
case '壬':
case '癸':
return '水旺';
default:
return '未知';
}
}
// 获取八字十神
public function getShishen() {
$shishen = array();
foreach ($this>data as $key => $value) {
$shishen[$key] = $this>getShishenByGan($value);
}
return $shishen;
}
// 根据干支获取十神
private function getShishenByGan($gan) {
switch ($gan) {
case '甲':
case '乙':
return '印';
case '丙':
case '丁':
return '食';
case '戊':
case '己':
return '财';
case '庚':
case '辛':
return '官';
case '壬':
case '癸':
return '杀';
default:
return '未知';
}
}
// 获取八字喜用神
public function getXiYongShen() {
$xiyongshen = array();
// 获取八字五行
$wuxing = $this>getWuxing();
// 获取八字生旺死绝
$shengwangsijue = $this>getShengWangSiJue();
// 获取八字十神
$shishen = $this>getShishen();
// 遍历八字数据
foreach ($this>data as $key => $value) {
// 判断五行是否旺
if ($shengwangsijue[$key] == '旺') {
// 获取五行相克的五行
$kexing = $this>getKexingByWuxing($wuxing[$key]);
// 获取五行相克的十神
$keshen = $this>getKeshenByWuxing($kexing);
// 获取五行相克的干支
foreach ($this>data as $key2 => $value2) {
if ($shishen[$key2] == $keshen) {
$xiyongshen[] = $value2;
}
}
}
}
return $xiyongshen;
}
// 根据五行获取相克的五行
private function getKexingByWuxing($wuxing) {
switch ($wuxing) {
case '木':
return '金';
case '火':
return '水';
case '土':
return '木';
case '金':
return '火';
case '水':
return '土';
default:
return '未知';
}
}
// 根据五行获取相克的十神
private function getKeshenByWuxing($wuxing) {
switch ($wuxing) {
case '木':
return '官';
case '火':
return '印';
case '土':
return '食';
case '金':
return '杀';
case '水':
return '财';
default:
return '未知';
}
}
// 测试
$data = array(
'年柱' => '甲子',
'月柱' => '丙寅',
'日柱' => '戊辰',
'时柱' => '庚午',
);
$bazi = new Bazi($data);
// 获取八字五行
$wuxing = $bazi>getWuxing();
print_r($wuxing);
// 获取八字生旺死绝
$shengwangsijue = $bazi>getShengWangSiJue();
print_r($shengwangsijue);
// 获取八字十神
$shishen = $bazi>getShishen();
print_r($shishen);
// 获取八字喜用神
$xiyongshen = $bazi>getXiYongShen();
print_r($xiyongshen);
```
免费网站:
八字网:
紫微命盘:
测八字:
滴天居士:
神巴巴:
付费网站:
八字命理网:
百度测算:
易经网:
中国传统文化网:
玄机阁:
''