{
  "id": 470116,
  "title": "A simple Feature Extraction",
  "url": "/competitions/hms-harmful-brain-activity-classification/discussion/470116",
  "author_name": "Joser",
  "post_date": "2024-01-23T04:41:20.618000",
  "votes": 1,
  "comment_count": 0,
  "views": 0,
  "content": "<p>`import numpy as np<br>\nfrom scipy.stats import skew, kurtosis<br>\nfrom scipy.stats.mstats import moment<br>\nfrom sklearn.preprocessing import StandardScaler</p>\n<p>def extract_eeg_features(eeg_data):<br>\n    \"\"\"<br>\n    Extract features from EEG data</p>\n<pre><code>:\n eeg_data: EEG data with shape (number of samples, time points, number of electrodes)\n\n:\n Feature matrix with shape (number of samples, number of features)\n\"\"\"\n\nnum_samples, num_time_points, num_electrodes = eeg_data.shape\nnum_features = 4 * num_electrodes  \nfeatures = np.zeros((num_samples, num_features))\n\n\nfor sample_idx in range(num_samples):\n    for electrode_idx in range(num_electrodes):\n        electrode_data = eeg_data[sample_idx, :, electrode_idx]\n        feature_idx = electrode_idx * 4\n\n        \n        features[sample_idx, feature_idx] = np.mean(electrode_data)\n        \n        features[sample_idx, feature_idx + 1] = np.std(electrode_data)\n        \n        features[sample_idx, feature_idx + 2] = np.min(electrode_data)\n        \n        features[sample_idx, feature_idx + 3] = np.max(electrode_data)\n\nreturn features\n</code></pre>\n<h1>Use the function to extract features</h1>\n<p>extracted_features = extract_eeg_features(all_eeg_data)</p>\n<h1>Output the shape of the extracted features matrix</h1>\n<p>print(\"Shape of extracted features:\", extracted_features.shape)<br>\n`<br>\nAnd I also check the NaN value of this feature values,replace the NaN values with mean.I saved the file and named it 'extracted_eeg_features.npy'.You can find the file <a href=\"https://www.kaggle.com/datasets/kitsuha/eeg-features\" target=\"_blank\">here</a>.I hope this will be helpful for you.</p>",
  "messages": [
    {
      "id": 2615352,
      "postDate": "2024-01-23T04:41:20.620Z",
      "content": "<p>`import numpy as np<br>\nfrom scipy.stats import skew, kurtosis<br>\nfrom scipy.stats.mstats import moment<br>\nfrom sklearn.preprocessing import StandardScaler</p>\n<p>def extract_eeg_features(eeg_data):<br>\n    \"\"\"<br>\n    Extract features from EEG data</p>\n<pre><code>:\n eeg_data: EEG data with shape (number of samples, time points, number of electrodes)\n\n:\n Feature matrix with shape (number of samples, number of features)\n\"\"\"\n\nnum_samples, num_time_points, num_electrodes = eeg_data.shape\nnum_features = 4 * num_electrodes  \nfeatures = np.zeros((num_samples, num_features))\n\n\nfor sample_idx in range(num_samples):\n    for electrode_idx in range(num_electrodes):\n        electrode_data = eeg_data[sample_idx, :, electrode_idx]\n        feature_idx = electrode_idx * 4\n\n        \n        features[sample_idx, feature_idx] = np.mean(electrode_data)\n        \n        features[sample_idx, feature_idx + 1] = np.std(electrode_data)\n        \n        features[sample_idx, feature_idx + 2] = np.min(electrode_data)\n        \n        features[sample_idx, feature_idx + 3] = np.max(electrode_data)\n\nreturn features\n</code></pre>\n<h1>Use the function to extract features</h1>\n<p>extracted_features = extract_eeg_features(all_eeg_data)</p>\n<h1>Output the shape of the extracted features matrix</h1>\n<p>print(\"Shape of extracted features:\", extracted_features.shape)<br>\n`<br>\nAnd I also check the NaN value of this feature values,replace the NaN values with mean.I saved the file and named it 'extracted_eeg_features.npy'.You can find the file <a href=\"https://www.kaggle.com/datasets/kitsuha/eeg-features\" target=\"_blank\">here</a>.I hope this will be helpful for you.</p>",
      "rawMarkdown": "`import numpy as np\nfrom scipy.stats import skew, kurtosis\nfrom scipy.stats.mstats import moment\nfrom sklearn.preprocessing import StandardScaler\n\ndef extract_eeg_features(eeg_data):\n    \"\"\"\n    Extract features from EEG data\n    \n    Parameters:\n    - eeg_data: EEG data with shape (number of samples, time points, number of electrodes)\n    \n    Returns:\n    - Feature matrix with shape (number of samples, number of features)\n    \"\"\"\n    # Initialize the feature matrix\n    num_samples, num_time_points, num_electrodes = eeg_data.shape\n    num_features = 4 * num_electrodes  # Mean, standard deviation, minimum, and maximum for each electrode\n    features = np.zeros((num_samples, num_features))\n\n    # Extract features\n    for sample_idx in range(num_samples):\n        for electrode_idx in range(num_electrodes):\n            electrode_data = eeg_data[sample_idx, :, electrode_idx]\n            feature_idx = electrode_idx * 4\n\n            # Mean\n            features[sample_idx, feature_idx] = np.mean(electrode_data)\n            # Standard deviation\n            features[sample_idx, feature_idx + 1] = np.std(electrode_data)\n            # Minimum\n            features[sample_idx, feature_idx + 2] = np.min(electrode_data)\n            # Maximum\n            features[sample_idx, feature_idx + 3] = np.max(electrode_data)\n\n    return features\n\n# Use the function to extract features\nextracted_features = extract_eeg_features(all_eeg_data)\n\n# Output the shape of the extracted features matrix\nprint(\"Shape of extracted features:\", extracted_features.shape)\n`\nAnd I also check the NaN value of this feature values,replace the NaN values with mean.I saved the file and named it 'extracted_eeg_features.npy'.You can find the file [here](https://www.kaggle.com/datasets/kitsuha/eeg-features).I hope this will be helpful for you.",
      "votes": 2
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2615352": "`import numpy as np\nfrom scipy.stats import skew, kurtosis\nfrom scipy.stats.mstats import moment\nfrom sklearn.preprocessing import StandardScaler\n\ndef extract_eeg_features(eeg_data):\n    \"\"\"\n    Extract features from EEG data\n    \n    Parameters:\n    - eeg_data: EEG data with shape (number of samples, time points, number of electrodes)\n    \n    Returns:\n    - Feature matrix with shape (number of samples, number of features)\n    \"\"\"\n    # Initialize the feature matrix\n    num_samples, num_time_points, num_electrodes = eeg_data.shape\n    num_features = 4 * num_electrodes  # Mean, standard deviation, minimum, and maximum for each electrode\n    features = np.zeros((num_samples, num_features))\n\n    # Extract features\n    for sample_idx in range(num_samples):\n        for electrode_idx in range(num_electrodes):\n            electrode_data = eeg_data[sample_idx, :, electrode_idx]\n            feature_idx = electrode_idx * 4\n\n            # Mean\n            features[sample_idx, feature_idx] = np.mean(electrode_data)\n            # Standard deviation\n            features[sample_idx, feature_idx + 1] = np.std(electrode_data)\n            # Minimum\n            features[sample_idx, feature_idx + 2] = np.min(electrode_data)\n            # Maximum\n            features[sample_idx, feature_idx + 3] = np.max(electrode_data)\n\n    return features\n\n# Use the function to extract features\nextracted_features = extract_eeg_features(all_eeg_data)\n\n# Output the shape of the extracted features matrix\nprint(\"Shape of extracted features:\", extracted_features.shape)\n`\nAnd I also check the NaN value of this feature values,replace the NaN values with mean.I saved the file and named it 'extracted_eeg_features.npy'.You can find the file [here](https://www.kaggle.com/datasets/kitsuha/eeg-features).I hope this will be helpful for you."
  }
}