Python Forum
Parallel processing - AttributeError: Can't get attribute 'sktimekmeans'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parallel processing - AttributeError: Can't get attribute 'sktimekmeans'
#1
Hi,

I am kind of new to Python as well as programming. I am running partitional clustering for time series data. It has 178 columns by 50000 rows. The below code is working fine as I tested for few rows. I would like to run for the entire rows (I waited for 2 hours but didn't finish). Hence wanted to try parallel processing.

This is my normal code:

k_means = TimeSeriesKMeans(
    n_clusters=8,  # Number of desired centers
    init_algorithm="forgy",  # Center initialisation technique
    max_iter=10,  # Maximum number of iterations for refinement on training set
    metric="dtw",  # Distance metric to use
    averaging_method="mean",  # Averaging technique to use
    random_state=1
)

###k_means.fit(X_df_melt3)

identified_clusters = k_means.fit_predict(X_df_melt3)
############################################################################
Below is something I tried based on different forums

from multiprocessing import Process
import os
import time
 

def sktimekmeans():
    kmeanss= TimeSeriesKMeans(
    n_clusters=8,  # Number of desired centers
    init_algorithm="forgy",  # Center initialisation technique
    max_iter=10,  # Maximum number of iterations for refinement on training set
    metric="dtw",  # Distance metric to use
    averaging_method="mean",  # Averaging technique to use
    random_state=1).fit(X_df_melt3)
    return kmeanss

if __name__ == '__main__':
    start_time = time.perf_counter()
 
    # Creates two processes
    p1 = multiprocessing.Process(target=sktimekmeans)
    # Starts both processes
    p1.start()
    print (p1)
First of all I am not sure, the code is correct. When I run this code, it throws an error :
Error:
traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\sound\anaconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main exitcode = _main(fd, parent_sentinel) File "C:\Users\sound\anaconda3\lib\multiprocessing\spawn.py", line 126, in _main self = reduction.pickle.load(from_parent) AttributeError: Can't get attribute 'sktimekmeans' on <module '__main__' (built-in)>
I tried to understand the error from different forums, but couldnt because of limited knowledge in python. I appreciate your help on this issue.
Larz60+ write Jun-18-2023, 09:10 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply
#2
from multiprocessing import Process

p1 = multiprocessing.Process(target=sktimekmeans)
Not sure what this does, but you import Process and try to start multiprocessing.Process. Also. you only start one Process, not 2.
    return kmeanss
You don't catch thr return. You may want a Manager object, a Queue, or logging depending on what type kmeanss is, and what you do with the return.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 790 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,757 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,928 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,399 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,685 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 7,143 Jul-06-2022, 10:55 AM
Last Post: deanhystad
  AttributeError: 'numpy.int32' object has no attribute 'split' rf_kartal 6 4,434 Jun-24-2022, 08:37 AM
Last Post: Anushka00
  AttributeError: 'list' object has no attribute 'upper' Anldra12 4 4,913 Apr-27-2022, 09:27 AM
Last Post: Anldra12
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 4,648 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 15,025 Jan-19-2022, 08:33 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020