Determine the container class of an object in Python 3

2017-10-25 Thread qrious

Class1 is instantiated in Class2 as follows. Class2 also contains another 
variable, say:

class Class2: 
class1 = Class1()
a = 0

I want to create a method myDef() in Class1 that can read or write to a. How do 
I access a from within myDef() to access a?

Calling Class2.a is not an option as Class1 does not have any knowledge about 
its container class a priori. Also, this will hardcode the path. I want to know 
of a built-in method (kind of equivalent of super() for inheritance) that will 
give me the container class reference, Class2 in this case. 

Thanks. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Data-structure for multiway associativity in Python

2018-01-27 Thread qrious


I need a data structure and a corresponding (hopefully fast) mechanism 
associated with it to do the following. While I am looking for the concept 
first, my preference for implementation of this will be in Python.

[c1, c2,..., cn] is a list of strings (for my own implementation, but could be 
any other type for the generic problem). There will be many hundreds, if not 
thousands, of such lists with no shared member.

The method getAssocList(e) will return lists of the lists for which e is an 
element.

Here a hash may be a way to go, but need help in figuring it out. Also, can 
there be a faster and more memory efficient solution other than hashes?
-- 
https://mail.python.org/mailman/listinfo/python-list


Sentiment analysis using sklearn

2018-01-27 Thread qrious
I am attempting to understand how scikit learn works for sentiment analysis and 
came across this blog post: 

https://marcobonzanini.wordpress.com/2015/01/19/sentiment-analysis-with-python-and-scikit-learn
 

The corresponding code is at this location: 

https://gist.github.com/bonzanini/c9248a239bbab0e0d42e 

My question is while trying to predict, why does the curr_class in Line 44 of 
the code need a classification (pos or neg) for the test data? After all, am I 
not trying to predict it? Without any initial value of curr_class, the program 
has a run time error.

Any help will be greatly appreciated.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sentiment analysis using sklearn

2018-01-27 Thread qrious
On Saturday, January 27, 2018 at 2:45:30 PM UTC-8, Terry Reedy wrote:
> On 1/27/2018 4:05 PM, qrious wrote:
> > I am attempting to understand how scikit learn works for sentiment analysis 
> > and came across this blog post:
> > 
> > https://marcobonzanini.wordpress.com/2015/01/19/sentiment-analysis-with-python-and-scikit-learn
> > 
> > The corresponding code is at this location:
> > 
> > https://gist.github.com/bonzanini/c9248a239bbab0e0d42e
> > 
> > My question is while trying to predict, why does the curr_class in Line 44 
> > of the code need a classification (pos or neg) for the test data? After 
> > all, am I not trying to predict it? Without any initial value of 
> > curr_class, the program has a run time error.
> 
> In order for the 'bot' to classify new samples, by learning the 
> difference between positive and negative samples, it needs to be trained 
> on existing samples that are 'correctly' classified.
> 
> 
> -- 
> Terry Jan Reedy

The training samples already do that. I think Dan's reply below makes sense.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sentiment analysis using sklearn

2018-01-27 Thread qrious
On Saturday, January 27, 2018 at 5:21:15 PM UTC-8, Dan Stromberg wrote:
> On Sat, Jan 27, 2018 at 1:05 PM, qrious wrote:
> > I am attempting to understand how scikit learn works for sentiment analysis 
> > and came across this blog post:
> >
> > https://marcobonzanini.wordpress.com/2015/01/19/sentiment-analysis-with-python-and-scikit-learn
> >
> > The corresponding code is at this location:
> >
> > https://gist.github.com/bonzanini/c9248a239bbab0e0d42e
> >
> > My question is while trying to predict, why does the curr_class in Line 44 
> > of the code need a classification (pos or neg) for the test data? After 
> > all, am I not trying to predict it? Without any initial value of 
> > curr_class, the program has a run time error.
> 
> I'm a real neophyte when it comes to modern AI, but I believe the
> intent is to divide your inputs into "training data" and "test data"
> and "real world data".
> 
> So you create your models using training data including correct
> classifications as part of the input.
> 
> And you check how well your models are doing on inputs they haven't
> seen before with test data, which also is classified in advance, to
> verify how well things are working.
> 
> And then you use real world, as-yet-unclassified data in production,
> after you've selected your best model, to derive a classification from
> what your model has seen in the past.
> 
> So both the training data and test data need accurate labels in
> advance, but the real world data trusts the model to do pretty well
> without further labeling.

Dan, 

Thanks and I was also thinking along this line: 'So both the training data and 
test data need accurate labels in advance'. It makes sense to me. 

For this part: 'the real world data trusts the model to do pretty well without 
further labeling', the question is: how do I do this using sklearn library 
functions? Is there some code example for using the actual data that needs 
prediction?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Data-structure for multiway associativity in Python

2018-01-28 Thread qrious
On Sunday, January 28, 2018 at 7:00:38 AM UTC-8, Steven D'Aprano wrote:

> 
> Since you specified that there are no lists with shared members, why 
> bother returning a list of lists? There will only ever be a single 
> matching list.
> 

That's correct. It will be a single list. My mistake in typing. 

> 
> To speed it up more, we'd need to know more information about how you are 
> using this. For example, if the values c1, ... d1, ... etc have some sort 
> of relationship, 

No relationship. 

> you might be able to generate some kind of multiway tree 
> that avoids having to search all of the thousands of lists before giving 
> up.

Which brings us to the Subject line of this thread. Without any relationship 
among the members, could we solve this using clever data structure? 
> 
> Are searches going to typically hit the same set c1... over and over 
> again? If so, then after matching, bring it to the front of the master 
> list. (You might want to use a deque for that.)
> 
> 
> 
> > Here a hash may be a way to go, but need help in figuring it out. Also,
> > can there be a faster and more memory efficient solution other than
> > hashes?
> 
> Probably not, not unless you have some sort of internal structure you can 
> take advantage of. For example, if all the strings in any group start 
> with the same letter, then you can dispatch directly to the right list:
> 
> data = {'c': {c1, c2, c3, ..., cn},
> 'd': {d1, ... } # and so on...
> }
> 
> def getAssocList(element):
> if element in data[element[0]]:
> return L
> raise ValueError('not found')
> 
> 
> But if there is no structure at all, and the elements in each list are 
> completely arbitrary, then there is nothing better than a linear search 
> through the entire collection of lists, looking at every single element 
> until you've matched what you're after.

The motivation of posting this thread is to explore if the above is true. 

> 
> But your description is pretty vague and for all I know what you actually 
> want is already a solved problem. Can you give more detail and cut-down 
> example of your data set? Say, two or three values per list, and two or 
> three lists.
> 
> 

First list = { 1, 2, 3} 
Second list = { 4, 5, 6} 
Third list = { 7, 8, 9} 

If I pass 9 as the argument, the return value of the function would be {7, 8}.


> -- 
> Steve

Thanks very much for your help and thoughts. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Python turtle: How to change icons

2016-11-25 Thread qrious

Hello All, 

I would like to change two graphical icons related to turtle graphics using 
Python:

a) One that shows up at the top left corner of the canvas window as in below. I 
believe this is coming from tk itself.

https://s22.postimg.org/tkjaxmh41/image.png 

b) The icon on the desktop as in below (in Windows): 

https://s13.postimg.org/n7ol0mdpz/icon.png 

Can this be done from within python code itself?

Thanks very much. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Synthesize a new series

2018-03-26 Thread qrious


I have a set of series of numbers. The set bears some common property about the 
series. For example, in one case, Series 1 can be the set of random number of 
odd numbers starting from 1 and Series N can be the set of random number of odd 
numbers starting from N. In another case, Series 1 can be the set of random 
number of odd numbers starting from 1, Series N can be the set of random number 
of (odd number)^N starting from 5 (arbitrary number), and so on. Each series 
can be of arbitrary length.

Even though the set members are 'similar' in properties, the exact relationship 
is not known.

I want to generate one additional member of the set that is 'similar' in 
properties with the existing one.

Questions:

1. Will Machine Learning be useful for this? If so, which specific term I 
should do a search on. Sorry for the lack of knowledge here.
2. I want to minimize the amount of coding, with preference for 0 coding. 
Which off-the-shelf tool (preference: open source and free) will be useful for 
this? If programming is needed, I would like to use Python and associated 
libraries.

-- 
https://mail.python.org/mailman/listinfo/python-list