시리즈: Music
python
32 줄
· 업데이트 2026-02-03
pca-feature-selection.py
Music/pca-feature-selection.py
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest, f_classif
import seaborn as sns
import matplotlib.pyplot as plt
# Load the dataset
iris = load_iris()
X = iris.data
y = iris.target
feature_names = iris.feature_names
target_names = iris.target_names
# Step 1: Apply feature selection
selector = SelectKBest(score_func=f_classif, k=2) # select top 2 features
X_selected = selector.fit_transform(X, y)
# Get selected feature names
selected_features = [feature_names[i] for i in selector.get_support(indices=True)]
print(f"Selected features: {selected_features}")
# Step 2: Create DataFrame for plotting
df_selected = pd.DataFrame(X_selected, columns=['Feature 1', 'Feature 2'])
df_selected['species'] = [target_names[i] for i in y]
# Step 3: Visualize
plt.figure(figsize=(8, 6))
sns.scatterplot(data=df_selected, x='Feature 1', y='Feature 2', hue='species', palette='Set2', s=80)
plt.title('Iris Dataset - Feature Selection (Top 2 Features by ANOVA F-value)')
plt.grid(True)
plt.tight_layout()
plt.show()
관련 글
Music
python
업데이트 2026-02-03
essentia.py
essentia.py — python source code from the Music learning materials (Music/essentia.py).
글 읽기 →
Music
python
업데이트 2026-02-03
ex01.py
ex01.py — python source code from the Music learning materials (Music/ex01.py).
글 읽기 →
Music
python
업데이트 2026-02-03
extract_midi_notes.py
extract_midi_notes.py — python source code from the Music learning materials (Music/extract_midi_notes.py).
글 읽기 →
Music
python
업데이트 2026-02-03
getMidiNotes.py
getMidiNotes.py — python source code from the Music learning materials (Music/getMidiNotes.py).
글 읽기 →
Music
python
업데이트 2026-02-03
markovchain_v2.py
markovchain_v2.py — python source code from the Music learning materials (Music/markovchain_v2.py).
글 읽기 →
Music
python
업데이트 2026-02-03
musc5211.py
musc5211.py — python source code from the Music learning materials (Music/musc5211.py).
글 읽기 →